From f260f424678f447d8dfe0593e1f08287e2967452 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 12:30:57 +0000 Subject: [PATCH 001/140] Auto-generated commit 2624c7dc4b3b0e9dc35233c11f2a977a3e1d0208 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 350 +++++++ bundle.js | 3 + bundle.js.map | 1 + package.json | 41 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 3594 insertions(+) create mode 100644 CONTRIBUTORS create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 README.md create mode 100644 bundle.js create mode 100644 bundle.js.map create mode 100644 package.json create mode 100644 stats.html diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..e5c896d --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,28 @@ +# This file is generated by tools/scripts/update_contributors. +# +# Contributors listed in alphabetical order. + +Ali Salesi +Athan Reines +Brendan Graetz +Bruno Fenzl +Christopher Dambamuromo +Dominik Moritz +Frank Kovacs +James +Jithin KS +Joey Reed +Joris Labie +Justin Dennison +Marcus +Matt Cochrane +Milan Raj +Momtchil Momtchev +Ognjen Jevremović +Philipp Burckhardt +Ricky Reusser +Ryan Seal +Seyyed Parsa Neshaei +Shraddheya Shendre +dorrin-sot <59933477+dorrin-sot@users.noreply.github.com> +rei2hu diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fcc9934 --- /dev/null +++ b/LICENSE @@ -0,0 +1,481 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by this +license (the "Software") to use, reproduce, display, distribute, execute, and +transmit the Software, and to prepare derivative works of the Software, and to +permit third-parties to whom the Software is furnished to do so, all subject to +the following: + +The copyright notices in the Software and this entire statement, including the +above license grant, this restriction and the following disclaimer, must be +included in all copies of the Software, in whole or in part, and all derivative +works of the Software, unless such copies or derivative works are solely in the +form of machine-executable object code generated by a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES +OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + + +DEPENDENCIES + +The library links against the following external libraries, which have their own +licenses: + +* OpenBLAS + +Copyright (c) 2011-2014, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* Electron + +Copyright (c) 2013-2017 GitHub Inc. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* Boost + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + + +* Cephes + +Copyright (c) 1984-2000 Stephen L. Moshier + +Some software in this archive may be from the book _Methods and Programs for +Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) +or from the Cephes Mathematical Library, a commercial product. In either event, +it is copyrighted by the author. What you see here may be used freely but it +comes with no support or guarantee. + +Stephen L. Moshier +moshier@na-net.ornl.gov + + + +ATTRIBUTION + +The library contains implementations from the following external libraries, +which have their own licenses: + +* FreeBSD + +Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* FDLIBM + +Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* Go + +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* SLATEC Common Mathematical Library + +Public domain. + + +* ESLint + +Copyright JS Foundation and other contributors, https://js.foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +* StatsFuns.jl + +Copyright (c) 2015: Dahua Lin. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* SpecialFunctions.jl + +The MIT License (MIT) + +Copyright (c) 2017 Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and others: + +https://github.com/JuliaMath/SpecialFunctions.jl/graphs/contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +* MT19937 + +Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..10e6ba1 --- /dev/null +++ b/NOTICE @@ -0,0 +1 @@ +Copyright (c) 2016-2022 The Stdlib Authors. diff --git a/README.md b/README.md new file mode 100644 index 0000000..84e38b6 --- /dev/null +++ b/README.md @@ -0,0 +1,350 @@ + + +# 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 + +To use in Observable, + +```javascript +sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@umd/bundle.js' ) +``` + +To include the bundle in a webpage, + +```html + +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + +``` + +#### sub2ind( shape, strides, offset, ...subscripts, mode ) + +Converts subscripts to a linear index. + +```javascript +var shape = [ 2, 2 ]; +var strides = [ 2, 1 ]; +var offset = 0; +var mode = [ 'throw' ]; + +var idx = sub2ind( shape, strides, offset, 1, 0, mode ); +// returns 2 +``` + +The function supports the following `modes`: + +- `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. + +```javascript +var shape = [ 2, 2 ]; +var strides = [ 2, 1 ]; +var offset = 0; + +var mode = [ 'wrap' ]; +var idx = sub2ind( shape, strides, offset, -2, 0, mode ); +// returns 0 + +mode = [ 'clamp' ]; +idx = sub2ind( shape, strides, offset, 10, 10, mode ); +// returns 3 +``` + +
+ + + + + +
+ +## Notes + +- When provided fewer `modes` than dimensions, the function recycles `modes` using modulo arithmetic. + + ```javascript + var shape = [ 2, 2, 2 ]; + var strides = [ 4, 2, 1 ]; + var offset = 0; + var mode = [ 'wrap', 'clamp' ]; + + var idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); + // returns 3 + ``` + +- When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. + + ```text + Dims: 2x2 + Buffer: [ 1, 2, 3, 4 ] + + View = [ a00, a01, + a10, a11 ] + + Strides: 2,1 + Offset: 0 + + View = [ 1, 2, + 3, 4 ] + + Strides: 2,-1 + Offset: 1 + + View = [ 2, 1, + 4, 3 ] + + Strides: -2,1 + Offset: 2 + + View = [ 3, 4, + 1, 2 ] + + Strides: -2,-1 + Offset: 3 + + View = [ 4, 3, + 2, 1 ] + ``` + + ```javascript + var shape = [ 2, 2 ]; + var strides = [ -2, 1 ]; + var offset = 2; + var mode = [ 'throw' ]; + + // From the perspective of a view... + var idx = sub2ind( shape, strides, 0, 0, 0, mode ); + // returns 0 + + idx = sub2ind( shape, strides, 0, 0, 1, mode ); + // returns 1 + + idx = sub2ind( shape, strides, 0, 1, 0, mode ); + // returns 2 + + idx = sub2ind( shape, strides, 0, 1, 1, mode ); + // returns 3 + + // From the perspective of an underlying buffer... + idx = sub2ind( shape, strides, offset, 0, 0, mode ); + // returns 2 + + idx = sub2ind( shape, strides, offset, 0, 1, mode ); + // returns 3 + + idx = sub2ind( shape, strides, offset, 1, 0, mode ); + // returns 0 + + idx = sub2ind( shape, strides, offset, 1, 1, mode ); + // returns 1 + ``` + + In short, from the perspective of a view, view data is always ordered. + +
+ + + + + +
+ +## Examples + + + +```html + + + + + + + + + + + + +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + +
+ +* * * + +## Notice + +This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. + +For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. + +#### Community + +[![Chat][chat-image]][chat-url] + +--- + +## License + +See [LICENSE][stdlib-license]. + + +## Copyright + +Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. + +
+ + + + + + + + diff --git a/bundle.js b/bundle.js new file mode 100644 index 0000000..8143d77 --- /dev/null +++ b/bundle.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(r="undefined"!=typeof globalThis?globalThis:r||self).sub2ind=e()}(this,(function(){"use strict";function r(r){if(r.__esModule)return r;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(r).forEach((function(t){var n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:function(){return r[t]}})})),e}var e="function"==typeof Object.defineProperty?Object.defineProperty:null;var t=function(){try{return e({},"x",{}),!0}catch(r){return!1}},n=Object.defineProperty,i=Object.prototype,a=i.toString,o=i.__defineGetter__,u=i.__defineSetter__,c=i.__lookupGetter__,s=i.__lookupSetter__;var f=function(r,e,t){var n,f,l,p;if("object"!=typeof r||null===r||"[object Array]"===a.call(r))throw new TypeError("invalid argument. First argument must be an object. Value: `"+r+"`.");if("object"!=typeof t||null===t||"[object Array]"===a.call(t))throw new TypeError("invalid argument. Property descriptor must be an object. Value: `"+t+"`.");if((f="value"in t)&&(c.call(r,e)||s.call(r,e)?(n=r.__proto__,r.__proto__=i,delete r[e],r[e]=t.value,r.__proto__=n):r[e]=t.value),l="get"in t,p="set"in t,f&&(l||p))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return l&&o&&o.call(r,e,t.get),p&&u&&u.call(r,e,t.set),r},l=n,p=f,v=t()?l:p;var g=function(r,e,t){v(r,e,{configurable:!1,enumerable:!1,writable:!1,value:t})},d=g;var h=function(r){return"string"==typeof r};var m=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var b=function(){return m&&"symbol"==typeof Symbol.toStringTag},w=Object.prototype.toString,y=w;var E=function(r){return y.call(r)},j=Object.prototype.hasOwnProperty;var P=function(r,e){return null!=r&&j.call(r,e)},_="function"==typeof Symbol?Symbol.toStringTag:"",T=P,x=_,O=w;var S=E,V=function(r){var e,t,n;if(null==r)return O.call(r);t=r[x],e=T(r,x);try{r[x]=void 0}catch(e){return O.call(r)}return n=O.call(r),e?r[x]=t:delete r[x],n},k=b()?V:S,I=String.prototype.valueOf;var A=k,R=function(r){try{return I.call(r),!0}catch(r){return!1}},$=b();var F=function(r){return"object"==typeof r&&(r instanceof String||($?R(r):"[object String]"===A(r)))},M=h,C=F;var N=d,B=function(r){return M(r)||C(r)},G=F;N(B,"isPrimitive",h),N(B,"isObject",G);var L=B,Z=Math.floor;var W=function(r){return Z(r)===r},X=W;var z=function(r){return"object"==typeof r&&null!==r&&"number"==typeof r.length&&X(r.length)&&r.length>=0&&r.length<=9007199254740991};var U=function(r){return"number"==typeof r},Y=Number,D=Y.prototype.toString;var q=k,H=Y,J=function(r){try{return D.call(r),!0}catch(r){return!1}},K=b();var Q=function(r){return"object"==typeof r&&(r instanceof H||(K?J(r):"[object Number]"===q(r)))},rr=U,er=Q;var tr=d,nr=function(r){return rr(r)||er(r)},ir=Q;tr(nr,"isPrimitive",U),tr(nr,"isObject",ir);var ar=nr,or=Number.POSITIVE_INFINITY,ur=Y.NEGATIVE_INFINITY,cr=or,sr=ur,fr=W;var lr=function(r){return rsr&&fr(r)},pr=ar.isPrimitive,vr=lr;var gr=function(r){return pr(r)&&vr(r)},dr=ar.isObject,hr=lr;var mr=function(r){return dr(r)&&hr(r.valueOf())},br=gr,wr=mr;var yr=d,Er=function(r){return br(r)||wr(r)},jr=mr;yr(Er,"isPrimitive",gr),yr(Er,"isObject",jr);var Pr=Er;var _r=function(r){return r!=r},Tr=ar.isPrimitive,xr=_r;var Or=function(r){return Tr(r)&&xr(r)},Sr=ar.isObject,Vr=_r;var kr=function(r){return Sr(r)&&Vr(r.valueOf())},Ir=Or,Ar=kr;var Rr=d,$r=function(r){return Ir(r)||Ar(r)},Fr=kr;Rr($r,"isPrimitive",Or),Rr($r,"isObject",Fr);var Mr=z,Cr=Pr.isPrimitive,Nr=L.isPrimitive,Br=$r.isPrimitive;var Gr=function(r,e,t){var n,i,a;if(!Mr(r)&&!Nr(r))throw new TypeError("invalid argument. First argument must be array-like. Value: `"+r+"`.");if(arguments.length<2)throw new Error("insufficient input arguments. Must provide a search value.");if(arguments.length>2){if(!Cr(t))throw new TypeError("invalid argument. Third argument must be an integer. Value: `"+t+"`.");(i=t)<0&&(i=0)}else i=0;if(Nr(r)){if(!Nr(e))throw new TypeError("invalid argument. Second argument must be a string primitive. Value: `"+e+"`.");return-1!==r.indexOf(e,i)}if(n=r.length,Br(e)){for(a=i;aJr&&r=0},ee=Pr.isObject;var te=function(r){return ee(r)&&r.valueOf()>=0},ne=re,ie=te;var ae=d,oe=function(r){return ne(r)||ie(r)},ue=te;ae(oe,"isPrimitive",re),ae(oe,"isObject",ue);var ce=oe.isPrimitive,se=L.isPrimitive;var fe=function(r,e){var t,n;if(!se(r))throw new TypeError("invalid argument. First argument must be a string. Value: `"+r+"`.");if(!ce(e))throw new TypeError("invalid argument. Second argument must be a nonnegative integer. Value: `"+e+"`.");if(0===r.length||0===e)return"";if(r.length*e>9007199254740991)throw new RangeError("invalid argument. Output string length exceeds maximum allowed string length.");for(t="",n=e;1==(1&n)&&(t+=r),0!==(n>>>=1);)r+=r;return t},le=Pr.isPrimitive,pe=L.isPrimitive;var ve=function(r,e,t){var n,i;if(!pe(r))throw new TypeError("invalid argument. First argument must be a string primitive. Value: `"+r+"`.");if(!pe(e))throw new TypeError("invalid argument. Second argument must be a string primitive. Value: `"+e+"`.");if(arguments.length>2){if(!le(t))throw new TypeError("invalid argument. Third argument must be an integer. Value: `"+t+"`.");n=t<0?r.length+t:t}else n=0;if(0===e.length)return!0;if(n<0||n+e.length>r.length)return!1;for(i=0;i=0&&"/"!==r[t];t--);return void 0===t||t<=0?r.replace(Te,"\\$&"):(e=(e=r.substring(1,t)).replace(Te,"\\$&"),r=r[0]+e+r.substring(t))},Oe=/./;var Se=function(r){return"boolean"==typeof r},Ve=Boolean.prototype.toString;var ke=k,Ie=function(r){try{return Ve.call(r),!0}catch(r){return!1}},Ae=b();var Re=function(r){return"object"==typeof r&&(r instanceof Boolean||(Ae?Ie(r):"[object Boolean]"===ke(r)))},$e=Se,Fe=Re;var Me=d,Ce=function(r){return $e(r)||Fe(r)},Ne=Re;Me(Ce,"isPrimitive",Se),Me(Ce,"isObject",Ne);var Be=Ce;var Ge=function(){return new Function("return this;")()},Le="object"==typeof self?self:null,Ze="object"==typeof window?window:null,We="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},Xe="object"==typeof We?We:null;module.exports=Xe;var ze=Be.isPrimitive,Ue=Ge,Ye=Le,De=Ze,qe=r(Object.freeze({__proto__:null}));var He=function(r){if(arguments.length){if(!ze(r))throw new TypeError("invalid argument. Must provide a boolean primitive. Value: `"+r+"`.");if(r)return Ue()}if(Ye)return Ye;if(De)return De;if(qe)return qe;throw new Error("unexpected error. Unable to resolve global object.")},Je=He(),Ke=Je.document&&Je.document.childNodes,Qe=Int8Array,rt=Oe,et=Ke,tt=Qe;var nt=function(){return"function"==typeof rt||"object"==typeof tt||"function"==typeof et};var it=function(){return/^\s*function\s*([^(]*)/i},at=it;d(at,"REGEXP",it());var ot=at,ut=k;var ct=Array.isArray?Array.isArray:function(r){return"[object Array]"===ut(r)};var st=function(r){return null!==r&&"object"==typeof r};d(st,"isObjectLikeArray",function(r){if("function"!=typeof r)throw new TypeError("invalid argument. Must provide a function. Value: `"+r+"`.");return function(e){var t,n;if(!ct(e))return!1;if(0===(t=e.length))return!1;for(n=0;n0&&(e-=1),t=n.toExponential(e)):t=n.toPrecision(r.precision),r.alternate||(t=At(t,Zt,"$1e"),t=At(t,Lt,"e"),t=At(t,Gt,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return t=At(t,Mt,"e+0$1"),t=At(t,Ct,"e-0$1"),r.alternate&&(t=At(t,Nt,"$1."),t=At(t,Bt,"$1.e")),n>=0&&r.sign&&(t=r.sign+t),t=Vt(r.specifier)?kt(t):It(t)},Xt=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;var zt=fe;var Ut=L.isPrimitive,Yt=Lr,Dt=_r,qt=Pe,Ht=Wt,Jt=function(r){var e,t,n,i,a;for(e=0,n=[],a=Xt.exec(r);a;)(t=r.slice(e,Xt.lastIndex-a[0].length)).length&&n.push(t),(i=o(a,n.length))&&n.push(i),e=Xt.lastIndex,a=Xt.exec(r);return(t=r.slice(e)).length&&n.push(t),n;function o(r){return{mapping:r[1]?parseInt(r[1],10):void 0,flags:r[2],width:r[3],hasPeriod:"."===r[4],precision:r[5],specifier:r[6]}}},Kt=function(r,e,t){var n=e-r.length;return n<0?r:r=t?r+zt(" ",n):zt(" ",n)+r},Qt=he,rn=String.fromCharCode;var en=function(r){var e,t,n,i,a,o,u,c,s;if(!Ut(r))throw new TypeError("invalid argument. Must provide a string. Value: `"+r+"`.");for(e=Jt(r),o="",u=1,c=0;c127)throw new Error("invalid character code. Value: "+n.arg);n.arg=Dt(a)?String(n.arg):rn(a)}break;case"e":case"E":case"f":case"F":case"g":case"G":n.hasPeriod||(n.precision=6),n.arg=Ht(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=Qt(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=Kt(n.arg,n.width,n.padRight)),o+=n.arg||"",u+=1}return o},tn=en;var nn=function(){var r,e,t,n,i,a,o,u,c,s,f,l;for(r=arguments[1],e=arguments[2],t=(a=arguments[3+(i=(n=arguments[0]).length)]).length,u=e,l=0;l=c&&(f=c-1);else if("wrap"===o)f<0?(f+=c)<0&&0!==(f%=c)&&(f+=c):f>=c&&(f-=c)>=c&&(f%=c);else if(f<0||f>=c)throw new RangeError(tn("invalid argument. Subscripts must not exceed array dimensions. Subscript: %u. Value: `%d`.",l,f));(s=r[l])<0&&0===e?u-=f*s:u+=f*s}return u};return nn})); +//# sourceMappingURL=bundle.js.map diff --git a/bundle.js.map b/bundle.js.map new file mode 100644 index 0000000..aff6364 --- /dev/null +++ b/bundle.js.map @@ -0,0 +1 @@ +{"version":3,"file":"bundle.js","sources":["../node_modules/@stdlib/utils-define-property/lib/define_property.js","../node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js","../node_modules/@stdlib/utils-define-property/lib/builtin.js","../node_modules/@stdlib/utils-define-property/lib/polyfill.js","../node_modules/@stdlib/utils-define-property/lib/index.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/primitive.js","../node_modules/@stdlib/assert-has-symbol-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostring.js","../node_modules/@stdlib/utils-native-class/lib/native_class.js","../node_modules/@stdlib/assert-has-own-property/lib/main.js","../node_modules/@stdlib/assert-has-own-property/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostringtag.js","../node_modules/@stdlib/utils-native-class/lib/polyfill.js","../node_modules/@stdlib/utils-native-class/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/try2valueof.js","../node_modules/@stdlib/assert-is-string/lib/valueof.js","../node_modules/@stdlib/assert-is-string/lib/object.js","../node_modules/@stdlib/assert-is-string/lib/main.js","../node_modules/@stdlib/assert-is-string/lib/index.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/is_integer.js","../node_modules/@stdlib/math-base-special-floor/lib/main.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-collection/lib/main.js","../node_modules/@stdlib/assert-is-collection/lib/index.js","../node_modules/@stdlib/constants-array-max-typed-array-length/lib/index.js","../node_modules/@stdlib/assert-is-number/lib/primitive.js","../node_modules/@stdlib/number-ctor/lib/index.js","../node_modules/@stdlib/number-ctor/lib/number.js","../node_modules/@stdlib/assert-is-number/lib/try2serialize.js","../node_modules/@stdlib/assert-is-number/lib/tostring.js","../node_modules/@stdlib/assert-is-number/lib/object.js","../node_modules/@stdlib/assert-is-number/lib/main.js","../node_modules/@stdlib/assert-is-number/lib/index.js","../node_modules/@stdlib/constants-float64-pinf/lib/index.js","../node_modules/@stdlib/constants-float64-ninf/lib/index.js","../node_modules/@stdlib/assert-is-integer/lib/integer.js","../node_modules/@stdlib/assert-is-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-integer/lib/object.js","../node_modules/@stdlib/assert-is-integer/lib/main.js","../node_modules/@stdlib/assert-is-integer/lib/index.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/main.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-nan/lib/primitive.js","../node_modules/@stdlib/assert-is-nan/lib/object.js","../node_modules/@stdlib/assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-contains/lib/contains.js","../node_modules/@stdlib/assert-contains/lib/index.js","../node_modules/@stdlib/string-lowercase/lib/lowercase.js","../node_modules/@stdlib/string-lowercase/lib/index.js","../node_modules/@stdlib/string-uppercase/lib/uppercase.js","../node_modules/@stdlib/string-uppercase/lib/index.js","../node_modules/@stdlib/assert-is-uppercase/lib/main.js","../node_modules/@stdlib/assert-is-uppercase/lib/index.js","../node_modules/@stdlib/math-base-assert-is-finite/lib/main.js","../node_modules/@stdlib/math-base-assert-is-finite/lib/index.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/object.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/main.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/index.js","../node_modules/@stdlib/string-repeat/lib/repeat.js","../node_modules/@stdlib/string-repeat/lib/index.js","../node_modules/@stdlib/constants-float64-max-safe-integer/lib/index.js","../node_modules/@stdlib/string-starts-with/lib/starts_with.js","../node_modules/@stdlib/string-format/lib/zero_pad.js","../node_modules/@stdlib/string-starts-with/lib/index.js","../node_modules/@stdlib/string-format/lib/format_integer.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/main.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/re.js","../node_modules/@stdlib/assert-is-boolean/lib/primitive.js","../node_modules/@stdlib/assert-is-boolean/lib/try2serialize.js","../node_modules/@stdlib/assert-is-boolean/lib/tostring.js","../node_modules/@stdlib/assert-is-boolean/lib/object.js","../node_modules/@stdlib/assert-is-boolean/lib/main.js","../node_modules/@stdlib/assert-is-boolean/lib/index.js","../node_modules/@stdlib/utils-global/lib/codegen.js","../node_modules/@stdlib/utils-global/lib/self.js","../node_modules/@stdlib/utils-global/lib/window.js","../node_modules/@stdlib/utils-global/lib/global.js","../node_modules/@stdlib/utils-global/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/nodelist.js","../node_modules/@stdlib/utils-global/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/typedarray.js","../node_modules/@stdlib/utils-type-of/lib/check.js","../node_modules/@stdlib/regexp-function-name/lib/main.js","../node_modules/@stdlib/regexp-function-name/lib/index.js","../node_modules/@stdlib/regexp-function-name/lib/regexp.js","../node_modules/@stdlib/assert-is-array/lib/main.js","../node_modules/@stdlib/assert-tools-array-function/lib/arrayfcn.js","../node_modules/@stdlib/assert-is-object-like/lib/main.js","../node_modules/@stdlib/assert-is-object-like/lib/index.js","../node_modules/@stdlib/assert-is-buffer/lib/main.js","../node_modules/@stdlib/utils-constructor-name/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/typeof.js","../node_modules/@stdlib/utils-constructor-name/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/polyfill.js","../node_modules/@stdlib/utils-type-of/lib/index.js","../node_modules/@stdlib/assert-is-function/lib/main.js","../node_modules/@stdlib/assert-is-function/lib/index.js","../node_modules/@stdlib/assert-is-regexp/lib/try2exec.js","../node_modules/@stdlib/assert-is-regexp/lib/exec.js","../node_modules/@stdlib/assert-is-regexp/lib/main.js","../node_modules/@stdlib/string-replace/lib/replace.js","../node_modules/@stdlib/math-base-special-abs/lib/main.js","../node_modules/@stdlib/string-format/lib/format_double.js","../node_modules/@stdlib/string-format/lib/tokenize.js","../node_modules/@stdlib/string-format/lib/space_pad.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js","../node_modules/@stdlib/string-format/lib/index.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\nvar main = ( typeof Object.defineProperty === 'function' ) ? Object.defineProperty : null;\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar defineProperty = require( './define_property.js' );\n\n\n// MAIN //\n\n/**\n* Tests for `Object.defineProperty` support.\n*\n* @private\n* @returns {boolean} boolean indicating if an environment has `Object.defineProperty` support\n*\n* @example\n* var bool = hasDefinePropertySupport();\n* // returns \n*/\nfunction hasDefinePropertySupport() {\n\t// Test basic support...\n\ttry {\n\t\tdefineProperty( {}, 'x', {} );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasDefinePropertySupport;\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// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @name defineProperty\n* @type {Function}\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nvar defineProperty = Object.defineProperty;\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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/* eslint-disable no-underscore-dangle, no-proto */\n\n'use strict';\n\n// VARIABLES //\n\nvar objectProtoype = Object.prototype;\nvar toStr = objectProtoype.toString;\nvar defineGetter = objectProtoype.__defineGetter__;\nvar defineSetter = objectProtoype.__defineSetter__;\nvar lookupGetter = objectProtoype.__lookupGetter__;\nvar lookupSetter = objectProtoype.__lookupSetter__;\n\n\n// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @param {Object} obj - object on which to define the property\n* @param {string} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nfunction defineProperty( obj, prop, descriptor ) {\n\tvar prototype;\n\tvar hasValue;\n\tvar hasGet;\n\tvar hasSet;\n\n\tif ( typeof obj !== 'object' || obj === null || toStr.call( obj ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an object. Value: `' + obj + '`.' );\n\t}\n\tif ( typeof descriptor !== 'object' || descriptor === null || toStr.call( descriptor ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. Property descriptor must be an object. Value: `' + descriptor + '`.' );\n\t}\n\thasValue = ( 'value' in descriptor );\n\tif ( hasValue ) {\n\t\tif (\n\t\t\tlookupGetter.call( obj, prop ) ||\n\t\t\tlookupSetter.call( obj, prop )\n\t\t) {\n\t\t\t// Override `__proto__` to avoid touching inherited accessors:\n\t\t\tprototype = obj.__proto__;\n\t\t\tobj.__proto__ = objectProtoype;\n\n\t\t\t// Delete property as existing getters/setters prevent assigning value to specified property:\n\t\t\tdelete obj[ prop ];\n\t\t\tobj[ prop ] = descriptor.value;\n\n\t\t\t// Restore original prototype:\n\t\t\tobj.__proto__ = prototype;\n\t\t} else {\n\t\t\tobj[ prop ] = descriptor.value;\n\t\t}\n\t}\n\thasGet = ( 'get' in descriptor );\n\thasSet = ( 'set' in descriptor );\n\n\tif ( hasValue && ( hasGet || hasSet ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.' );\n\t}\n\n\tif ( hasGet && defineGetter ) {\n\t\tdefineGetter.call( obj, prop, descriptor.get );\n\t}\n\tif ( hasSet && defineSetter ) {\n\t\tdefineSetter.call( obj, prop, descriptor.set );\n\t}\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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* Define (or modify) an object property.\n*\n* @module @stdlib/utils-define-property\n*\n* @example\n* var defineProperty = require( '@stdlib/utils-define-property' );\n*\n* var obj = {};\n* defineProperty( obj, 'foo', {\n* 'value': 'bar',\n* 'writable': false,\n* 'configurable': false,\n* 'enumerable': false\n* });\n* obj.foo = 'boop'; // => throws\n*/\n\n// MODULES //\n\nvar hasDefinePropertySupport = require( './has_define_property_support.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar defineProperty;\nif ( hasDefinePropertySupport() ) {\n\tdefineProperty = builtin;\n} else {\n\tdefineProperty = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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\nvar defineProperty = require( '@stdlib/utils-define-property' );\n\n\n// MAIN //\n\n/**\n* Defines a non-enumerable read-only property.\n*\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setNonEnumerableReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Define a non-enumerable read-only property.\n*\n* @module @stdlib/utils-define-nonenumerable-read-only-property\n*\n* @example\n* var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\n*\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\n\n// MODULES //\n\nvar setNonEnumerableReadOnly = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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// MAIN //\n\n/**\n* Tests for native `Symbol` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Symbol` support\n*\n* @example\n* var bool = hasSymbolSupport();\n* // returns \n*/\nfunction hasSymbolSupport() {\n\treturn (\n\t\ttypeof Symbol === 'function' &&\n\t\ttypeof Symbol( 'foo' ) === 'symbol'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasSymbolSupport;\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\nvar hasSymbols = require( '@stdlib/assert-has-symbol-support' );\n\n\n// VARIABLES //\n\nvar FLG = hasSymbols();\n\n\n// MAIN //\n\n/**\n* Tests for native `toStringTag` support.\n*\n* @returns {boolean} boolean indicating if an environment has `toStringTag` support\n*\n* @example\n* var bool = hasToStringTagSupport();\n* // returns \n*/\nfunction hasToStringTagSupport() {\n\treturn ( FLG && typeof Symbol.toStringTag === 'symbol' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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* Test for native `toStringTag` support.\n*\n* @module @stdlib/assert-has-tostringtag-support\n*\n* @example\n* var hasToStringTagSupport = require( '@stdlib/assert-has-tostringtag-support' );\n*\n* var bool = hasToStringTagSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasToStringTagSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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// MAIN //\n\nvar toStr = Object.prototype.toString;\n\n\n// EXPORTS //\n\nmodule.exports = toStr;\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\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification (via the internal property `[[Class]]`) of an object.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\treturn toStr.call( v );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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// FUNCTIONS //\n\nvar has = Object.prototype.hasOwnProperty;\n\n\n// MAIN //\n\n/**\n* Tests if an object has a specified property.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object has a specified property\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'bap' );\n* // returns false\n*/\nfunction hasOwnProp( value, property ) {\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\treturn has.call( value, property );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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* Test whether an object has a specified property.\n*\n* @module @stdlib/assert-has-own-property\n*\n* @example\n* var hasOwnProp = require( '@stdlib/assert-has-own-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* bool = hasOwnProp( beep, 'bop' );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasOwnProp = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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// MAIN //\n\nvar toStrTag = ( typeof Symbol === 'function' ) ? Symbol.toStringTag : '';\n\n\n// EXPORTS //\n\nmodule.exports = toStrTag;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar toStringTag = require( './tostringtag.js' );\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification of an object in environments supporting `Symbol.toStringTag`.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\tvar isOwn;\n\tvar tag;\n\tvar out;\n\n\tif ( v === null || v === void 0 ) {\n\t\treturn toStr.call( v );\n\t}\n\ttag = v[ toStringTag ];\n\tisOwn = hasOwnProp( v, toStringTag );\n\n\t// Attempt to override the `toStringTag` property. For built-ins having a `Symbol.toStringTag` property (e.g., `JSON`, `Math`, etc), the `Symbol.toStringTag` property is read-only (e.g., , so we need to wrap in a `try/catch`.\n\ttry {\n\t\tv[ toStringTag ] = void 0;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn toStr.call( v );\n\t}\n\tout = toStr.call( v );\n\n\tif ( isOwn ) {\n\t\tv[ toStringTag ] = tag;\n\t} else {\n\t\tdelete v[ toStringTag ];\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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* Return a string value indicating a specification defined classification of an object.\n*\n* @module @stdlib/utils-native-class\n*\n* @example\n* var nativeClass = require( '@stdlib/utils-native-class' );\n*\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* function Beep() {\n* return this;\n* }\n* str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\n\n// MODULES //\n\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar builtin = require( './native_class.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar nativeClass;\nif ( hasToStringTag() ) {\n\tnativeClass = polyfill;\n} else {\n\tnativeClass = builtin;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to extract a string value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a string can be extracted\n*/\nfunction test( value ) {\n\ttry {\n\t\tvalueOf.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar valueOf = String.prototype.valueOf; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2valueof.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string object\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns false\n*/\nfunction isString( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof String ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object String]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a string\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*/\nfunction isString( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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* Test if a value is a string.\n*\n* @module @stdlib/assert-is-string\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' );\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 5 );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isObject;\n*\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 'beep' );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isString = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isString, 'isPrimitive', isPrimitive );\nsetReadOnly( isString, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Tests if a finite double-precision floating-point number is an integer.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\treturn (floor(x) === x);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// TODO: implementation (?)\n\n/**\n* Rounds a double-precision floating-point number toward negative infinity.\n*\n* @param {number} x - input value\n* @returns {number} rounded value\n*\n* @example\n* var v = floor( -4.2 );\n* // returns -5.0\n*\n* @example\n* var v = floor( 9.99999 );\n* // returns 9.0\n*\n* @example\n* var v = floor( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = floor( NaN );\n* // returns NaN\n*/\nvar floor = Math.floor; // eslint-disable-line stdlib/no-builtin-math\n\n\n// EXPORTS //\n\nmodule.exports = floor;\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* Test if a finite double-precision floating-point number is an integer.\n*\n* @module @stdlib/math-base-assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/math-base-assert-is-integer' );\n*\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* bool = isInteger( 3.14 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isInteger = require( './is_integer.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a collection.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is a collection\n*\n* @example\n* var bool = isCollection( [] );\n* // returns true\n*\n* @example\n* var bool = isCollection( {} );\n* // returns false\n*/\nfunction isCollection( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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* Test if a value is a collection.\n*\n* @module @stdlib/assert-is-collection\n*\n* @example\n* var isCollection = require( '@stdlib/assert-is-collection' );\n*\n* var bool = isCollection( [] );\n* // returns true\n*\n* bool = isCollection( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isCollection = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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* Maximum length of a typed array.\n*\n* @module @stdlib/constants-array-max-typed-array-length\n*\n* @example\n* var MAX_TYPED_ARRAY_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n* // returns 9007199254740991\n*/\n\n// MAIN //\n\n/**\n* Maximum length of a typed array.\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n*/\nvar MAX_TYPED_ARRAY_LENGTH = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = MAX_TYPED_ARRAY_LENGTH;\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* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Constructor which returns a `Number` object.\n*\n* @module @stdlib/number-ctor\n*\n* @example\n* var Number = require( '@stdlib/number-ctor' );\n*\n* var v = new Number( 10.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar Number = require( './number.js' );\n\n\n// EXPORTS //\n\nmodule.exports = Number;\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// EXPORTS //\n\nmodule.exports = Number; // eslint-disable-line stdlib/require-globals\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Number.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar Number = require( '@stdlib/number-ctor' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\nfunction isNumber( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Number ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Number]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a number\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( null );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Test if a value is a number.\n*\n* @module @stdlib/assert-is-number\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' );\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( null );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isObject;\n*\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNumber, 'isPrimitive', isPrimitive );\nsetReadOnly( isNumber, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Double-precision floating-point positive infinity.\n*\n* @module @stdlib/constants-float64-pinf\n* @type {number}\n*\n* @example\n* var FLOAT64_PINF = require( '@stdlib/constants-float64-pinf' );\n* // returns Infinity\n*/\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point positive infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point positive infinity has the bit sequence\n*\n* ```binarystring\n* 0 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.POSITIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_PINF = Number.POSITIVE_INFINITY; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_PINF;\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* Double-precision floating-point negative infinity.\n*\n* @module @stdlib/constants-float64-ninf\n* @type {number}\n*\n* @example\n* var FLOAT64_NINF = require( '@stdlib/constants-float64-ninf' );\n* // returns -Infinity\n*/\n\n// MODULES //\n\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point negative infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point negative infinity has the bit sequence\n*\n* ```binarystring\n* 1 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.NEGATIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_NINF = Number.NEGATIVE_INFINITY;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_NINF;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar isInt = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests if a number primitive is an integer value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a number primitive is an integer value\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tvalue < PINF &&\n\t\tvalue > NINF &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having an integer value\n*\n* @example\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having an integer value\n*\n* @example\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an integer\n*\n* @example\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isInteger( -3.14 );\n* // returns false\n*\n* @example\n* var bool = isInteger( null );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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* Test if a value is an integer.\n*\n* @module @stdlib/assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/assert-is-integer' );\n*\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isInteger( -3.14 );\n* // returns false\n*\n* bool = isInteger( null );\n* // returns false\n*\n* @example\n* // Use interface to check for integer primitives...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n*\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*\n* @example\n* // Use interface to check for integer objects...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n*\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is `NaN`.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 7.0 );\n* // returns false\n*/\nfunction isnan( x ) {\n\treturn ( x !== x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a double-precision floating-point numeric value is `NaN`.\n*\n* @module @stdlib/math-base-assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/math-base-assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 7.0 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isnan = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a `NaN` number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a `NaN` number primitive\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a value of `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a value of `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( null );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a value is `NaN`.\n*\n* @module @stdlib/assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( null );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isObject;\n*\n* var bool = isnan( NaN );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isnan = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isnan, 'isPrimitive', isPrimitive );\nsetReadOnly( isnan, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if an array-like value contains a search value.\n*\n* @param {(Collection|string)} val - input value\n* @param {*} searchValue - search value\n* @param {integer} [position=0] - position at which to start searching for `searchValue`\n* @throws {TypeError} first argument must be array-like\n* @throws {Error} must provide a search value\n* @throws {TypeError} second argument must be a primitive string primitive when the first argument is a string\n* @throws {TypeError} third argument must be an integer\n* @returns {boolean} boolean indicating whether one value contains another\n*\n* @example\n* var bool = contains( 'last man standing', 'stand' );\n* // returns true\n*\n* @example\n* var bool = contains( [ 1, 2, 3, 4 ], 2 );\n* // returns true\n*\n* @example\n* var bool = contains( 'presidential election', 'president' );\n* // returns true\n*\n* @example\n* var bool = contains( [ NaN, 2, 3, 4 ], NaN );\n* // returns true\n*\n* @example\n* var bool = contains( 'javaScript', 'js' );\n* // returns false\n*\n* @example\n* var bool = contains( [ 1, 2, 3, {} ], {} );\n* // returns false\n*\n* @example\n* var bool = contains( 'Hidden Treasures', '' );\n* // returns true\n*/\nfunction contains( val, searchValue, position ) {\n\tvar len;\n\tvar pos;\n\tvar i;\n\tif ( !isCollection( val ) && !isString( val ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be array-like. Value: `' + val + '`.' );\n\t}\n\tif ( arguments.length < 2 ) {\n\t\tthrow new Error( 'insufficient input arguments. Must provide a search value.' );\n\t}\n\tif ( arguments.length > 2 ) {\n\t\tif ( !isInteger( position ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Third argument must be an integer. Value: `' + position + '`.' );\n\t\t}\n\t\tpos = position;\n\t\tif ( pos < 0 ) {\n\t\t\tpos = 0;\n\t\t}\n\t} else {\n\t\tpos = 0;\n\t}\n\tif ( isString( val ) ) {\n\t\tif ( !isString( searchValue ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive. Value: `' + searchValue + '`.' );\n\t\t}\n\t\treturn val.indexOf( searchValue, pos ) !== -1;\n\t}\n\tlen = val.length;\n\tif ( isnan( searchValue ) ) {\n\t\tfor ( i = pos; i < len; i++ ) {\n\t\t\tif ( isnan( val[ i ] ) ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\tfor ( i = pos; i < len; i++ ) {\n\t\tif ( val[ i ] === searchValue ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = contains;\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* Test if an array-like value contains another value.\n*\n* @module @stdlib/assert-contains\n*\n* @example\n* var contains = require( '@stdlib/assert-contains' );\n*\n* var bool = contains( 'Hello World', 'World' );\n* // returns true\n*\n* bool = contains( 'Hello World', 'world' );\n* // returns false\n*\n* bool = contains( [ 1, 2, 3, 4 ], 2 );\n* // returns true\n*\n* bool = contains( [ NaN, 2, 3, 4 ], NaN );\n* // returns true\n*/\n\n// MODULES //\n\nvar contains = require( './contains.js' );\n\n\n// EXPORTS //\n\nmodule.exports = contains;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Converts a string to lowercase.\n*\n* @param {string} str - string to convert\n* @throws {TypeError} must provide a primitive string\n* @returns {string} lowercase string\n*\n* @example\n* var str = lowercase( 'bEEp' );\n* // returns 'beep'\n*/\nfunction lowercase( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a primitive string. Value: `'+str+'`.' );\n\t}\n\treturn str.toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = lowercase;\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 a string to lowercase.\n*\n* @module @stdlib/string-lowercase\n*\n* @example\n* var lowercase = require( '@stdlib/string-lowercase' );\n*\n* var str = lowercase( 'bEEp' );\n* // returns 'beep'\n*/\n\n// MODULES //\n\nvar lowercase = require( './lowercase.js' );\n\n\n// EXPORTS //\n\nmodule.exports = lowercase;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Converts a string to uppercase.\n*\n* @param {string} str - string to convert\n* @throws {TypeError} must provide a primitive string\n* @returns {string} uppercase string\n*\n* @example\n* var str = uppercase( 'bEEp' );\n* // returns 'BEEP'\n*/\nfunction uppercase( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a primitive string. Value: `'+str+'`.' );\n\t}\n\treturn str.toUpperCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = uppercase;\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 a string to uppercase.\n*\n* @module @stdlib/string-uppercase\n*\n* @example\n* var uppercase = require( '@stdlib/string-uppercase' );\n*\n* var str = uppercase( 'bEEp' );\n* // returns 'BEEP'\n*/\n\n// MODULES //\n\nvar uppercase = require( './uppercase.js' );\n\n\n// EXPORTS //\n\nmodule.exports = uppercase;\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\nvar lowercase = require( '@stdlib/string-lowercase' );\nvar uppercase = require( '@stdlib/string-uppercase' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is an uppercase string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an uppercase string\n*\n* @example\n* var bool = isUppercase( 'HELLO' );\n* // returns true\n*\n* @example\n* var bool = isUppercase( 'World' );\n* // returns false\n*\n* @example\n* var bool = isUppercase( '!' );\n* // returns false\n*\n* @example\n* var bool = isUppercase( 'salt and light' );\n* // returns false\n*/\nfunction isUppercase( value ) {\n\treturn (\n\t\tisString( value ) &&\n\t\tvalue === uppercase( value ) &&\n\t\tvalue !== lowercase( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUppercase;\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* Test if a value is an uppercase string.\n*\n* @module @stdlib/assert-is-uppercase\n*\n* @example\n* var isUppercase = require( '@stdlib/assert-is-uppercase' );\n*\n* var bool = isUppercase( 'HELLO' );\n* // returns true\n*\n* bool = isUppercase( 'World' );\n* // returns false\n*/\n\n// MODULES //\n\nvar isUppercase = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isUppercase;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is finite.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is finite\n*\n* @example\n* var bool = isfinite( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isfinite( -2.0e64 );\n* // returns true\n*\n* @example\n* var bool = isfinite( Infinity );\n* // returns false\n*\n* @example\n* var bool = isfinite( -Infinity );\n* // returns false\n*/\nfunction isfinite( x ) {\n\treturn (\n\t\t// NaN check (x !== x ):\n\t\tx === x &&\n\n\t\t// +-infinity check:\n\t\tx > NINF &&\n\t\tx < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isfinite;\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* Test if a double-precision floating-point numeric value is finite.\n*\n* @module @stdlib/math-base-assert-is-finite\n*\n* @example\n* var isfinite = require( '@stdlib/math-base-assert-is-finite' );\n*\n* var bool = isfinite( 5.0 );\n* // returns true\n*\n* bool = isfinite( -2.0e64 );\n* // returns true\n*\n* bool = isfinite( Infinity );\n* // returns false\n*\n* bool = isfinite( -Infinity );\n* // returns false\n*/\n\n// MODULES //\n\nvar isfinite = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isfinite;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue.valueOf() >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a nonnegative integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a nonnegative integer\n*\n* @example\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( null );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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* Test if a value is a nonnegative integer.\n*\n* @module @stdlib/assert-is-nonnegative-integer\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' );\n*\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* bool = isNonNegativeInteger( null );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isObject;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNonNegativeInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isNonNegativeInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar FLOAT64_MAX_SAFE_INTEGER = require( '@stdlib/constants-float64-max-safe-integer' );\n\n\n// MAIN //\n\n/**\n* Repeats a string a specified number of times and returns the concatenated result.\n*\n* ## Method\n*\n* The algorithmic trick used in the implementation is to treat string concatenation the same as binary addition (i.e., any natural number (nonnegative integer) can be expressed as a sum of powers of two).\n*\n* For example,\n*\n* ```text\n* n = 10 => 1010 => 2^3 + 2^0 + 2^1 + 2^0\n* ```\n*\n* We can produce a 10-repeat string by \"adding\" the results of a 8-repeat string and a 2-repeat string.\n*\n* The implementation is then as follows:\n*\n* 1. Let `s` be the string to be repeated and `o` be an output string.\n*\n* 2. Initialize an output string `o`.\n*\n* 3. Check the least significant bit to determine if the current `s` string should be \"added\" to the output \"total\".\n*\n* - if the bit is a one, add\n* - otherwise, move on\n*\n* 4. Double the string `s` by adding `s` to `s`.\n*\n* 5. Right-shift the bits of `n`.\n*\n* 6. Check if we have shifted off all bits.\n*\n* - if yes, done.\n* - otherwise, move on\n*\n* 7. Repeat 3-6.\n*\n* The result is that, as the string is repeated, we continually check to see if the doubled string is one which we want to add to our \"total\".\n*\n* The algorithm runs in `O(log_2(n))` compared to `O(n)`.\n*\n*\n* @param {string} str - string to repeat\n* @param {NonNegativeInteger} n - number of times to repeat the string\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {RangeError} output string length must not exceed maximum allowed string length\n* @returns {string} repeated string\n*\n* @example\n* var str = repeat( 'a', 5 );\n* // returns 'aaaaa'\n*\n* @example\n* var str = repeat( '', 100 );\n* // returns ''\n*\n* @example\n* var str = repeat( 'beep', 0 );\n* // returns ''\n*/\nfunction repeat( str, n ) {\n\tvar rpt;\n\tvar cnt;\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string. Value: `' + str + '`.' );\n\t}\n\tif ( !isNonNegativeInteger( n ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a nonnegative integer. Value: `' + n + '`.' );\n\t}\n\tif ( str.length === 0 || n === 0 ) {\n\t\treturn '';\n\t}\n\t// Check that output string will not exceed the maximum string length:\n\tif ( str.length * n > FLOAT64_MAX_SAFE_INTEGER ) {\n\t\tthrow new RangeError( 'invalid argument. Output string length exceeds maximum allowed string length.' );\n\t}\n\trpt = '';\n\tcnt = n;\n\tfor ( ; ; ) {\n\t\t// If the count is odd, append the current concatenated string:\n\t\tif ( (cnt&1) === 1 ) {\n\t\t\trpt += str;\n\t\t}\n\t\t// Right-shift the bits:\n\t\tcnt >>>= 1;\n\t\tif ( cnt === 0 ) {\n\t\t\tbreak;\n\t\t}\n\t\t// Double the string:\n\t\tstr += str;\n\t}\n\treturn rpt;\n}\n\n\n// EXPORTS //\n\nmodule.exports = repeat;\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* Repeat a string a specified number of times and return the concatenated result.\n*\n* @module @stdlib/string-repeat\n*\n* @example\n* var replace = require( '@stdlib/string-repeat' );\n*\n* var str = repeat( 'a', 5 );\n* // returns 'aaaaa'\n*\n* str = repeat( '', 100 );\n* // returns ''\n*\n* str = repeat( 'beep', 0 );\n* // returns ''\n*/\n\n// MODULES //\n\nvar repeat = require( './repeat.js' );\n\n\n// EXPORTS //\n\nmodule.exports = repeat;\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* Maximum safe double-precision floating-point integer.\n*\n* @module @stdlib/constants-float64-max-safe-integer\n* @type {number}\n*\n* @example\n* var FLOAT64_MAX_SAFE_INTEGER = require( '@stdlib/constants-float64-max-safe-integer' );\n* // returns 9007199254740991\n*/\n\n\n// MAIN //\n\n/**\n* Maximum safe double-precision floating-point integer.\n*\n* ## Notes\n*\n* The integer has the value\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n* @see [Safe Integers]{@link http://www.2ality.com/2013/10/safe-integers.html}\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_MAX_SAFE_INTEGER = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_MAX_SAFE_INTEGER;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a string starts with the characters of another string.\n*\n* @param {string} str - input string\n* @param {string} search - search string\n* @param {integer} [position=0] - position at which to start searching\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument must be a string primitive\n* @throws {TypeError} third argument must be an integer\n* @returns {boolean} boolean indicating if the input string starts with the search string\n*\n* @example\n* var bool = startsWith( 'Remember the story I used to tell you when you were a boy?', 'Remember' );\n* // returns true\n*\n* @example\n* var bool = startsWith( 'Remember the story I used to tell you when you were a boy?', 'Remember, remember' );\n* // returns false\n*\n* @example\n* var bool = startsWith( 'To be, or not to be, that is the question.', 'To be' );\n* // returns true\n*\n* @example\n* var bool = startsWith( 'To be, or not to be, that is the question.', 'to be' );\n* // returns false\n*\n* @example\n* var bool = startsWith( 'To be, or not to be, that is the question.', 'to be', 14 );\n* // returns true\n*\n* @example\n* var bool = startsWith( 'To be, or not to be, that is the question.', 'quest', -9 );\n* // returns true\n*/\nfunction startsWith( str, search, position ) {\n\tvar pos;\n\tvar i;\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( !isString( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive. Value: `' + search + '`.' );\n\t}\n\tif ( arguments.length > 2 ) {\n\t\tif ( !isInteger( position ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Third argument must be an integer. Value: `' + position + '`.' );\n\t\t}\n\t\tif ( position < 0 ) {\n\t\t\tpos = str.length + position;\n\t\t} else {\n\t\t\tpos = position;\n\t\t}\n\t} else {\n\t\tpos = 0;\n\t}\n\tif ( search.length === 0 ) {\n\t\treturn true;\n\t}\n\tif (\n\t\tpos < 0 ||\n\t\tpos + search.length > str.length\n\t) {\n\t\treturn false;\n\t}\n\tfor ( i = 0; i < search.length; i++ ) {\n\t\tif ( str.charCodeAt( pos + i ) !== search.charCodeAt( i ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n\n// EXPORTS //\n\nmodule.exports = startsWith;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar repeat = require( '@stdlib/string-repeat' );\nvar startsWith = require( '@stdlib/string-starts-with' );\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWith( str, '-' ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + repeat( '0', pad ) :\n\t\trepeat( '0', pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = zeroPad;\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* Test if a string starts with the characters of another string.\n*\n* @module @stdlib/string-starts-with\n*\n* @example\n* var startsWith = require( '@stdlib/string-starts-with' );\n*\n* var str = 'Fair is foul, and foul is fair, hover through fog and filthy air';\n* var bool = startsWith( str, 'Fair' );\n* // returns true\n*\n* bool = startsWith( str, 'fair' );\n* // returns false\n*\n* bool = startsWith( str, 'foul', 8 );\n* // returns true\n*\n* bool = startsWith( str, 'filthy', -10 );\n* // returns true\n*/\n\n// MODULES //\n\nvar startsWith = require( './starts_with.js' );\n\n\n// EXPORTS //\n\nmodule.exports = startsWith;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isUppercase = require( '@stdlib/assert-is-uppercase' );\nvar uppercase = require( '@stdlib/string-uppercase' );\nvar lowercase = require( '@stdlib/string-lowercase' );\nvar isfinite = require( '@stdlib/math-base-assert-is-finite' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar zeroPad = require( './zero_pad.js' );\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isfinite( i ) ) {\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( isUppercase( token.specifier ) ) ?\n\t\t\tuppercase( out ) :\n\t\t\tlowercase( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = formatInteger;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// VARIABLES //\n\nvar RE_CHARS = /[-\\/\\\\^$*+?.()|[\\]{}]/g; // eslint-disable-line no-useless-escape\n\n\n// MAIN //\n\n/**\n* Escapes a regular expression string.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} first argument must be a string primitive\n* @returns {string} escaped string\n*\n* @example\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\nfunction rescape( str ) {\n\tvar len;\n\tvar s;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Check if the string starts with a forward slash...\n\tif ( str[ 0 ] === '/' ) {\n\t\t// Find the last forward slash...\n\t\tlen = str.length;\n\t\tfor ( i = len-1; i >= 0; i-- ) {\n\t\t\tif ( str[ i ] === '/' ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:\n\tif ( i === void 0 || i <= 0 ) {\n\t\treturn str.replace( RE_CHARS, '\\\\$&' );\n\t}\n\t// We need to de-construct the string...\n\ts = str.substring( 1, i );\n\n\t// Only escape the characters between the `/`:\n\ts = s.replace( RE_CHARS, '\\\\$&' );\n\n\t// Reassemble:\n\tstr = str[ 0 ] + s + str.substring( i );\n\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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* Escape a regular expression string or pattern.\n*\n* @module @stdlib/utils-escape-regexp-string\n*\n* @example\n* var rescape = require( '@stdlib/utils-escape-regexp-string' );\n*\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\n\n// MODULES //\n\nvar rescape = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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\nvar RE = /./;\n\n\n// EXPORTS //\n\nmodule.exports = RE;\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* Tests if a value is a boolean primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean primitive\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns false\n*/\nfunction isBoolean( value ) {\n\treturn ( typeof value === 'boolean' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Boolean.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean object\n*\n* @example\n* var bool = isBoolean( true );\n* // returns false\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Boolean ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Boolean]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a boolean\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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* Test if a value is a boolean.\n*\n* @module @stdlib/assert-is-boolean\n*\n* @example\n* var isBoolean = require( '@stdlib/assert-is-boolean' );\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* // Use interface to check for boolean primitives...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( true ) );\n* // returns false\n*\n* @example\n* // Use interface to check for boolean objects...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isObject;\n*\n* var bool = isBoolean( true );\n* // returns false\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isBoolean = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isBoolean, 'isPrimitive', isPrimitive );\nsetReadOnly( isBoolean, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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// MAIN //\n\n/**\n* Returns the global object using code generation.\n*\n* @private\n* @returns {Object} global object\n*/\nfunction getGlobal() {\n\treturn new Function( 'return this;' )(); // eslint-disable-line no-new-func\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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// MAIN //\n\nvar obj = ( typeof self === 'object' ) ? self : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof window === 'object' ) ? window : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof global === 'object' ) ? global : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar getThis = require( './codegen.js' );\nvar Self = require( './self.js' );\nvar Win = require( './window.js' );\nvar Global = require( './global.js' );\n\n\n// MAIN //\n\n/**\n* Returns the global object.\n*\n* ## Notes\n*\n* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.\n*\n* @param {boolean} [codegen=false] - boolean indicating whether to use code generation to resolve the global object\n* @throws {TypeError} must provide a boolean\n* @throws {Error} unable to resolve global object\n* @returns {Object} global object\n*\n* @example\n* var g = getGlobal();\n* // returns {...}\n*/\nfunction getGlobal( codegen ) {\n\tif ( arguments.length ) {\n\t\tif ( !isBoolean( codegen ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Must provide a boolean primitive. Value: `'+codegen+'`.' );\n\t\t}\n\t\tif ( codegen ) {\n\t\t\treturn getThis();\n\t\t}\n\t\t// Fall through...\n\t}\n\t// Case: browsers and web workers\n\tif ( Self ) {\n\t\treturn Self;\n\t}\n\t// Case: browsers\n\tif ( Win ) {\n\t\treturn Win;\n\t}\n\t// Case: Node.js\n\tif ( Global ) {\n\t\treturn Global;\n\t}\n\t// Case: unknown\n\tthrow new Error( 'unexpected error. Unable to resolve global object.' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar getGlobal = require( '@stdlib/utils-global' );\n\n\n// MAIN //\n\nvar root = getGlobal();\nvar nodeList = root.document && root.document.childNodes;\n\n\n// EXPORTS //\n\nmodule.exports = nodeList;\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* Return the global object.\n*\n* @module @stdlib/utils-global\n*\n* @example\n* var getGlobal = require( '@stdlib/utils-global' );\n*\n* var g = getGlobal();\n* // returns {...}\n*/\n\n// MODULES //\n\nvar getGlobal = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar typedarray = Int8Array; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = typedarray;\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\nvar RE = require( './fixtures/re.js' );\nvar nodeList = require( './fixtures/nodelist.js' );\nvar typedarray = require( './fixtures/typedarray.js' );\n\n\n// MAIN //\n\n/**\n* Checks whether a polyfill is needed when using the `typeof` operator.\n*\n* @private\n* @returns {boolean} boolean indicating whether a polyfill is needed\n*/\nfunction check() {\n\tif (\n\t\t// Chrome 1-12 returns 'function' for regular expression instances (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof):\n\t\ttypeof RE === 'function' ||\n\n\t\t// Safari 8 returns 'object' for typed array and weak map constructors (underscore #1929):\n\t\ttypeof typedarray === 'object' ||\n\n\t\t// PhantomJS 1.9 returns 'function' for `NodeList` instances (underscore #2236):\n\t\ttypeof nodeList === 'function'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\nfunction reFunctionName() {\n\treturn /^\\s*function\\s*([^(]*)/i;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @module @stdlib/regexp-function-name\n*\n* @example\n* var reFunctionName = require( '@stdlib/regexp-function-name' );\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reFunctionName = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reFunctionName, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\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\nvar reFunctionName = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Captures everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* Regular expression: `/^\\s*function\\s*([^(]*)/i`\n*\n* - `/^\\s*`\n* - Match zero or more spaces at beginning\n*\n* - `function`\n* - Match the word `function`\n*\n* - `\\s*`\n* - Match zero or more spaces after the word `function`\n*\n* - `()`\n* - Capture\n*\n* - `[^(]*`\n* - Match anything except a left parenthesis `(` zero or more times\n*\n* - `/i`\n* - ignore case\n*\n* @constant\n* @type {RegExp}\n* @default /^\\s*function\\s*([^(]*)/i\n*/\nvar RE_FUNCTION_NAME = reFunctionName();\n\n\n// EXPORTS //\n\nmodule.exports = RE_FUNCTION_NAME;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar f;\n\n\n// FUNCTIONS //\n\n/**\n* Tests if a value is an array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an array\n*\n* @example\n* var bool = isArray( [] );\n* // returns true\n*\n* @example\n* var bool = isArray( {} );\n* // returns false\n*/\nfunction isArray( value ) {\n\treturn ( nativeClass( value ) === '[object Array]' );\n}\n\n\n// MAIN //\n\nif ( Array.isArray ) {\n\tf = Array.isArray;\n} else {\n\tf = isArray;\n}\n\n\n// EXPORTS //\n\nmodule.exports = f;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Returns a function which tests if every element in an array passes a test condition.\n*\n* @param {Function} predicate - function to apply\n* @throws {TypeError} must provide a function\n* @returns {Function} an array function\n*\n* @example\n* var isOdd = require( '@stdlib/assert-is-odd' );\n*\n* var arr1 = [ 1, 3, 5, 7 ];\n* var arr2 = [ 3, 5, 8 ];\n*\n* var validate = arrayfcn( isOdd );\n*\n* var bool = validate( arr1 );\n* // returns true\n*\n* bool = validate( arr2 );\n* // returns false\n*/\nfunction arrayfcn( predicate ) {\n\tif ( typeof predicate !== 'function' ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a function. Value: `' + predicate + '`.' );\n\t}\n\treturn every;\n\n\t/**\n\t* Tests if every element in an array passes a test condition.\n\t*\n\t* @private\n\t* @param {*} value - value to test\n\t* @returns {boolean} boolean indicating whether a value is an array for which all elements pass a test condition\n\t*/\n\tfunction every( value ) {\n\t\tvar len;\n\t\tvar i;\n\t\tif ( !isArray( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tlen = value.length;\n\t\tif ( len === 0 ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( predicate( value[ i ] ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayfcn;\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* Tests if a value is object-like.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is object-like\n*\n* @example\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( [] );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( null );\n* // returns false\n*/\nfunction isObjectLike( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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* Test if a value is object-like.\n*\n* @module @stdlib/assert-is-object-like\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' );\n*\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* bool = isObjectLike( [] );\n* // returns true\n*\n* bool = isObjectLike( null );\n* // returns false\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' ).isObjectLikeArray;\n*\n* var bool = isObjectLike( [ {}, [] ] );\n* // returns true\n*\n* bool = isObjectLike( [ {}, '3.0' ] );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar arrayfun = require( '@stdlib/assert-tools-array-function' );\nvar isObjectLike = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( isObjectLike, 'isObjectLikeArray', arrayfun( isObjectLike ) );\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Buffer instance.\n*\n* @param {*} value - value to validate\n* @returns {boolean} boolean indicating if a value is a Buffer instance\n*\n* @example\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( new Buffer( [1,2,3,4] ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( {} );\n* // returns false\n*\n* @example\n* var v = isBuffer( [] );\n* // returns false\n*/\nfunction isBuffer( value ) {\n\treturn (\n\t\tisObjectLike( value ) &&\n\t\t(\n\t\t\t// eslint-disable-next-line no-underscore-dangle\n\t\t\tvalue._isBuffer || // for envs missing Object.prototype.constructor (e.g., Safari 5-7)\n\t\t\t(\n\t\t\t\tvalue.constructor &&\n\n\t\t\t\t// WARNING: `typeof` is not a foolproof check, as certain envs consider RegExp and NodeList instances to be functions\n\t\t\t\ttypeof value.constructor.isBuffer === 'function' &&\n\t\t\t\tvalue.constructor.isBuffer( value )\n\t\t\t)\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar RE = require( '@stdlib/regexp-function-name' ).REGEXP;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\n\n\n// MAIN //\n\n/**\n* Determines the name of a value's constructor.\n*\n* @param {*} v - input value\n* @returns {string} name of a value's constructor\n*\n* @example\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* @example\n* var v = constructorName( 5 );\n* // returns 'Number'\n*\n* @example\n* var v = constructorName( null );\n* // returns 'Null'\n*\n* @example\n* var v = constructorName( undefined );\n* // returns 'Undefined'\n*\n* @example\n* var v = constructorName( function noop() {} );\n* // returns 'Function'\n*/\nfunction constructorName( v ) {\n\tvar match;\n\tvar name;\n\tvar ctor;\n\tname = nativeClass( v ).slice( 8, -1 );\n\tif ( (name === 'Object' || name === 'Error') && v.constructor ) {\n\t\tctor = v.constructor;\n\t\tif ( typeof ctor.name === 'string' ) {\n\t\t\treturn ctor.name;\n\t\t}\n\t\tmatch = RE.exec( ctor.toString() );\n\t\tif ( match ) {\n\t\t\treturn match[ 1 ];\n\t\t}\n\t}\n\tif ( isBuffer( v ) ) {\n\t\treturn 'Buffer';\n\t}\n\treturn name;\n}\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// NOTES //\n\n/*\n* Built-in `typeof` operator behavior:\n*\n* ```text\n* typeof null => 'object'\n* typeof undefined => 'undefined'\n* typeof 'a' => 'string'\n* typeof 5 => 'number'\n* typeof NaN => 'number'\n* typeof true => 'boolean'\n* typeof false => 'boolean'\n* typeof {} => 'object'\n* typeof [] => 'object'\n* typeof function foo(){} => 'function'\n* typeof function* foo(){} => 'object'\n* typeof Symbol() => 'symbol'\n* ```\n*\n*/\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\tvar type;\n\n\t// Address `typeof null` => `object` (see http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null):\n\tif ( v === null ) {\n\t\treturn 'null';\n\t}\n\ttype = typeof v;\n\n\t// If the `typeof` operator returned something other than `object`, we are done. Otherwise, we need to check for an internal class name or search for a constructor.\n\tif ( type === 'object' ) {\n\t\treturn ctorName( v ).toLowerCase();\n\t}\n\treturn type;\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine the name of a value's constructor.\n*\n* @module @stdlib/utils-constructor-name\n*\n* @example\n* var constructorName = require( '@stdlib/utils-constructor-name' );\n*\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* v = constructorName( {} );\n* // returns 'Object'\n*\n* v = constructorName( true );\n* // returns 'Boolean'\n*/\n\n// MODULES //\n\nvar constructorName = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\treturn ctorName( v ).toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine a value's type.\n*\n* @module @stdlib/utils-type-of\n*\n* @example\n* var typeOf = require( '@stdlib/utils-type-of' );\n*\n* var str = typeOf( 'a' );\n* // returns 'string'\n*\n* str = typeOf( 5 );\n* // returns 'number'\n*/\n\n// MODULES //\n\nvar usePolyfill = require( './check.js' );\nvar typeOf = require( './typeof.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main = ( usePolyfill() ) ? polyfill : typeOf;\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar typeOf = require( '@stdlib/utils-type-of' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a function.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a function\n*\n* @example\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\nfunction isFunction( value ) {\n\t// Note: cannot use `typeof` directly, as various browser engines incorrectly return `'function'` when operating on non-function objects, such as regular expressions and NodeLists.\n\treturn ( typeOf( value ) === 'function' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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* Test if a value is a function.\n*\n* @module @stdlib/assert-is-function\n*\n* @example\n* var isFunction = require( '@stdlib/assert-is-function' );\n*\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\n\n// MODULES //\n\nvar isFunction = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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\nvar exec = require( './exec.js' );\n\n\n// MAIN //\n\n/**\n* Attempts to call a `RegExp` method.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if able to call a `RegExp` method\n*/\nfunction test( value ) {\n\ttry {\n\t\texec.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar exec = RegExp.prototype.exec; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = exec;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2exec.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a regular expression.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a regular expression\n*\n* @example\n* var bool = isRegExp( /\\.+/ );\n* // returns true\n*\n* @example\n* var bool = isRegExp( {} );\n* // returns false\n*/\nfunction isRegExp( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof RegExp ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object RegExp]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isRegExp;\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\nvar rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument argument must be a string primitive or regular expression\n* @throws {TypeError} third argument must be a string primitive or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive or regular expression. Value: `' + search + '`.' );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( 'invalid argument. Third argument must be a string primitive or replacement function. Value: `' + newval + '`.' );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Computes the absolute value of a double-precision floating-point number `x`.\n*\n* @param {number} x - input value\n* @returns {number} absolute value\n*\n* @example\n* var v = abs( -1.0 );\n* // returns 1.0\n*\n* @example\n* var v = abs( 2.0 );\n* // returns 2.0\n*\n* @example\n* var v = abs( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = abs( -0.0 );\n* // returns 0.0\n*\n* @example\n* var v = abs( NaN );\n* // returns NaN\n*/\nfunction abs( x ) {\n\treturn Math.abs( x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = abs;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isUppercase = require( '@stdlib/assert-is-uppercase' );\nvar uppercase = require( '@stdlib/string-uppercase' );\nvar lowercase = require( '@stdlib/string-lowercase' );\nvar replace = require( '@stdlib/string-replace' );\nvar isfinite = require( '@stdlib/math-base-assert-is-finite' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar abs = require( '@stdlib/math-base-special-abs' );\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isfinite( f ) ) {\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( isUppercase( token.specifier ) ) ?\n\t\tuppercase( out ) :\n\t\tlowercase( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// MAIN //\n\n/**\n* Tokenizes a string.\n*\n* @private\n* @param {string} str - input string\n* @returns {Array} tokens\n*/\nfunction tokenize( str ) {\n\tvar lastIndex;\n\tvar content;\n\tvar tokens;\n\tvar parsed;\n\tvar match;\n\n\tlastIndex = 0;\n\ttokens = [];\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( lastIndex, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\tparsed = parse( match, tokens.length );\n\t\tif ( parsed ) {\n\t\t\ttokens.push( parsed );\n\t\t}\n\t\tlastIndex = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( lastIndex );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n\n\t/**\n\t* Parses a delimeter.\n\t*\n\t* @private\n\t* @param {Array} match - regular expression match\n\t* @returns {Object} delimeter token object\n\t*/\n\tfunction parse( match ) {\n\t\treturn {\n\t\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t\t'flags': match[ 2 ],\n\t\t\t'width': match[ 3 ],\n\t\t\t'hasPeriod': match[ 4 ] === '.',\n\t\t\t'precision': match[ 5 ],\n\t\t\t'specifier': match[ 6 ]\n\t\t};\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = tokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar repeat = require( '@stdlib/string-repeat' );\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + repeat( ' ', pad ) :\n\t\trepeat( ' ', pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar contains = require( '@stdlib/assert-contains' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar formatInteger = require( './format_integer.js' );\nvar formatDouble = require( './format_double.js' );\nvar tokenize = require( './tokenize.js' );\nvar spacePad = require( './space_pad.js' );\nvar zeroPad = require( './zero_pad.js' );\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} must provide a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a string. Value: `' + str + '`.' );\n\t}\n\ttokens = tokenize( str );\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t}\n\t\telse {\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = !contains( flags, '-' );\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.precision === '*' && token.hasPeriod ) {\n\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\ttoken.hasPeriod = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( token.hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( token.hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !token.hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = format;\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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: %u. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Insert supplied variable values into a format string.\n*\n* @module @stdlib/string-format\n*\n* @example\n* var format = require( '@stdlib/string-format' );\n*\n* var out = format( '%s %s!', 'Hello', 'World' );\n* // returns 'Hello World!'\n*\n* out = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\n\n// MODULES //\n\nvar format = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = format;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"],"names":["defineProperty","Object","has_define_property_support","err","builtin","objectProtoype","prototype","toStr","toString","defineGetter","__defineGetter__","defineSetter","__defineSetter__","lookupGetter","__lookupGetter__","lookupSetter","__lookupSetter__","polyfill","obj","prop","descriptor","hasValue","hasGet","hasSet","call","TypeError","__proto__","value","Error","get","set","require$$1","require$$2","require$$0","main","configurable","enumerable","writable","lib","primitive","FLG","Symbol","hasSymbols","toStringTag","tostring","native_class","v","has","hasOwnProperty","property","toStrTag","hasOwnProp","isOwn","tag","out","valueOf","String","nativeClass","test","object","isPrimitive","isObject","setReadOnly","isString","require$$3","floor","Math","x","isInteger","length","Number","isNumber","POSITIVE_INFINITY","NEGATIVE_INFINITY","PINF","NINF","isInt","integer","isNan","isnan","isCollection","contains_1","val","searchValue","position","len","pos","i","arguments","indexOf","str","toLowerCase","toUpperCase","lowercase","uppercase","isNonNegativeInteger","n","rpt","cnt","RangeError","starts_with","search","charCodeAt","repeat","startsWith","zero_pad","width","right","negative","pad","substr","isUppercase","isfinite","require$$4","zeroPad","require$$5","format_integer","token","base","specifier","arg","parseInt","precision","padRight","sign","alternate","charAt","RE_CHARS","s","replace","substring","re","Boolean","isBoolean","codegen","Function","self_1","self","window_1","window","global","module","exports","getThis","Self","Win","Global","root","nodeList","document","childNodes","typedarray","Int8Array","RE","check_1","reFunctionName","isArray","Array","isObjectLike","predicate","arrayfun","REGEXP","isBuffer","_isBuffer","constructor","match","name","ctor","slice","exec","ctorName","typeOf","type","RegExp","rescape","isFunction","isRegExp","newval","abs","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","format_double","digits","f","parseFloat","toExponential","toFixed","toPrecision","contains","formatInteger","formatDouble","tokenize","lastIndex","content","tokens","parsed","push","parse","mapping","flags","hasPeriod","spacePad","require$$7","fromCharCode","flag","num","j","padZeros","maxWidth","format","strides","offset","nmodes","shape","ndims","modes","mode","idx","m"],"mappings":";ifAsBA,ICAIA,EDA0C,mBAA1BC,OAAOD,eAAkCC,OAAOD,eAAiB,KC4BrF,IAAAE,EAbA,WAEC,IAEC,OADAF,EAAgB,GAAI,IAAK,KAClB,EACN,MAAQG,GACT,OAAO,ICiBTC,EALqBH,OAAOD,eC/BxBK,EAAiBJ,OAAOK,UACxBC,EAAQF,EAAeG,SACvBC,EAAeJ,EAAeK,iBAC9BC,EAAeN,EAAeO,iBAC9BC,EAAeR,EAAeS,iBAC9BC,EAAeV,EAAeW,iBAuFlC,IAAAC,EAnDA,SAAyBC,EAAKC,EAAMC,GACnC,IAAId,EACAe,EACAC,EACAC,EAEJ,GAAoB,iBAARL,GAA4B,OAARA,GAAsC,mBAAtBX,EAAMiB,KAAMN,GAC3D,MAAM,IAAIO,UAAW,+DAAiEP,EAAM,MAE7F,GAA2B,iBAAfE,GAA0C,OAAfA,GAAoD,mBAA7Bb,EAAMiB,KAAMJ,GACzE,MAAM,IAAIK,UAAW,oEAAsEL,EAAa,MAyBzG,IAvBAC,EAAa,UAAWD,KAGtBP,EAAaW,KAAMN,EAAKC,IACxBJ,EAAaS,KAAMN,EAAKC,IAGxBb,EAAYY,EAAIQ,UAChBR,EAAIQ,UAAYrB,SAGTa,EAAKC,GACZD,EAAKC,GAASC,EAAWO,MAGzBT,EAAIQ,UAAYpB,GAEhBY,EAAKC,GAASC,EAAWO,OAG3BL,EAAW,QAASF,EACpBG,EAAW,QAASH,EAEfC,IAAcC,GAAUC,GAC5B,MAAM,IAAIK,MAAO,wHASlB,OANKN,GAAUb,GACdA,EAAae,KAAMN,EAAKC,EAAMC,EAAWS,KAErCN,GAAUZ,GACdA,EAAaa,KAAMN,EAAKC,EAAMC,EAAWU,KAEnCZ,GCrEJd,EAAU2B,EACVd,EAAWe,ECpBXhC,EDkB2BiC,IASb7B,EAEAa,ECMlB,IAAAiB,EAZA,SAAmChB,EAAKC,EAAMQ,GAC7C3B,EAAgBkB,EAAKC,EAAM,CAC1BgB,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZV,MAASA,KCJXW,EAL+BL,ECA/B,IAAAM,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCMjB,ICdIa,EDIJ,WACC,MACmB,mBAAXC,QACoB,iBAApBA,OAAQ,OCPPC,GAqBV,ICTAJ,EDEA,WACC,OAASE,GAAqC,iBAAvBC,OAAOE,aEf/BC,EALY3C,OAAOK,UAAUE,SCAzBD,EAAQ0B,EAiCZ,IAAAY,EAPA,SAAsBC,GACrB,OAAOvC,EAAMiB,KAAMsB,IC3BhBC,EAAM9C,OAAOK,UAAU0C,eAyC3B,ICjBAV,EDIA,SAAqBX,EAAOsB,GAC3B,OACCtB,MAAAA,GAKMoB,EAAIvB,KAAMG,EAAOsB,IEnCrBC,EAA+B,mBAAXT,OAA0BA,OAAOE,YAAc,GCAnEQ,EAAalB,EACbU,EDIaO,ECHb3C,EAAQyB,EAwDZ,ICpCI5B,EAAU2B,EACVd,EDKJ,SAAsB6B,GACrB,IAAIM,EACAC,EACAC,EAEJ,GAAKR,MAAAA,EACJ,OAAOvC,EAAMiB,KAAMsB,GAEpBO,EAAMP,EAAGH,GACTS,EAAQD,EAAYL,EAAGH,GAGvB,IACCG,EAAGH,QAAgB,EAClB,MAAQxC,GACT,OAAOI,EAAMiB,KAAMsB,GASpB,OAPAQ,EAAM/C,EAAMiB,KAAMsB,GAEbM,EACJN,EAAGH,GAAgBU,SAEZP,EAAGH,GAEJW,GCdRhB,EAjBqBL,IASNhB,EAEAb,EChCXmD,ECDUC,OAAOlD,UAAUiD,QDyB/B,IEvBIE,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADA4B,EAAQ/B,KAAMG,IACP,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBP,IA0CrB,IAAA0B,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB6B,SAGjBhB,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MClCpBiC,EAAc3B,EACd4B,EAAW9B,EA0Bf,ICSI+B,EAAc7B,EACd8B,EDjBJ,SAAmBpC,GAClB,OAASiC,EAAajC,IAAWkC,EAAUlC,ICkBxCkC,EAAWG,EAKfF,EAAaC,EAAU,cANL/B,GAOlB8B,EAAaC,EAAU,WAAYF,GAKnC,IAAAvB,EAAiByB,EClDbE,ECsBQC,KAAKD,MDIjB,IENA3B,EFDA,SAAoB6B,GACnB,OAAQF,EAAME,KAAOA,GGpBlBC,EAAYnC,EAkChB,ICdAK,EDAA,SAAuBX,GACtB,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAM0C,QACbD,EAAWzC,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QENqB,kBCE7B,IAAA9B,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCAjBW,ECjBiBgC,OCAb9D,ECASyB,EAMS3B,UAAUE,SDkBhC,IEvBIiD,EAAc1B,EACduC,EAAStC,EACT0B,EFSJ,SAAe/B,GACd,IAEC,OADAnB,EAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IETLqC,EARiBP,IA2CrB,IAAA0B,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB2C,IAGjB9B,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MCnCpBiC,GAAc3B,EACd4B,GAAW9B,EAkCf,ICOI+B,GAAc7B,EACdsC,GDfJ,SAAmB5C,GAClB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,EAKfF,GAAaS,GAAU,cANLvC,GAOlB8B,GAAaS,GAAU,WAAYV,IAKnC,IAAAvB,GAAiBiC,GCvBjBjC,GALmBgC,OAAOE,kBCS1BlC,GA1BaL,EAqBawC,kBChCtBC,GAAOzC,GACP0C,GAAO5C,GACP6C,GAAQ5C,EAuBZ,IAAA6C,GAXA,SAAoBlD,GACnB,OACCA,EAAQ+C,IACR/C,EAAQgD,IACRC,GAAOjD,IClBL4C,GAAWtC,GAAsC2B,YACjDgB,GAAQ7C,GA6BZ,IAAAQ,GAVA,SAAoBZ,GACnB,OACC4C,GAAU5C,IACViD,GAAOjD,ICvBL4C,GAAWtC,GAAsC4B,SACjDe,GAAQ7C,GA6BZ,IAAA4B,GAVA,SAAoBhC,GACnB,OACC4C,GAAU5C,IACViD,GAAOjD,EAAM4B,YCvBXK,GAAc3B,GACd4B,GAAW9B,GAkCf,ICMI+B,GAAc7B,EACdmC,GDdJ,SAAoBzC,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICexCkC,GAAWG,GAKfF,GAAaM,GAAW,cANNpC,IAOlB8B,GAAaM,GAAW,WAAYP,IAKpC,IAAAvB,GAAiB8B,GClCjB,ICDA9B,GDNA,SAAgB6B,GACf,OAASA,GAAMA,GEfZI,GAAWtC,GAAsC2B,YACjDkB,GAAQ/C,GAiCZ,IAAAQ,GAVA,SAAgBZ,GACf,OACC4C,GAAU5C,IACVmD,GAAOnD,IC3BL4C,GAAWtC,GAAsC4B,SACjDiB,GAAQ/C,GA6BZ,IAAA4B,GAVA,SAAgBhC,GACf,OACC4C,GAAU5C,IACVmD,GAAOnD,EAAM4B,YCvBXK,GAAc3B,GACd4B,GAAW9B,GAkCf,ICOI+B,GAAc7B,EACd8C,GDfJ,SAAgBpD,GACf,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAaiB,GAAO,cANF/C,IAOlB8B,GAAaiB,GAAO,WAAYlB,IAKhC,ICxDImB,GAAe/C,EACfmC,GAAYrC,GAAuC6B,YACnDG,GAAW/B,EAAsC4B,YACjDmB,GDqDaA,GCrD8BnB,YA4F/C,IAAAqB,GA/CA,SAAmBC,EAAKC,EAAaC,GACpC,IAAIC,EACAC,EACAC,EACJ,IAAMP,GAAcE,KAAUnB,GAAUmB,GACvC,MAAM,IAAIzD,UAAW,gEAAkEyD,EAAM,MAE9F,GAAKM,UAAUnB,OAAS,EACvB,MAAM,IAAIzC,MAAO,8DAElB,GAAK4D,UAAUnB,OAAS,EAAI,CAC3B,IAAMD,GAAWgB,GAChB,MAAM,IAAI3D,UAAW,gEAAkE2D,EAAW,OAEnGE,EAAMF,GACK,IACVE,EAAM,QAGPA,EAAM,EAEP,GAAKvB,GAAUmB,GAAQ,CACtB,IAAMnB,GAAUoB,GACf,MAAM,IAAI1D,UAAW,yEAA2E0D,EAAc,MAE/G,OAA4C,IAArCD,EAAIO,QAASN,EAAaG,GAGlC,GADAD,EAAMH,EAAIb,OACLU,GAAOI,GAAgB,CAC3B,IAAMI,EAAID,EAAKC,EAAIF,EAAKE,IACvB,GAAKR,GAAOG,EAAKK,IAChB,OAAO,EAGT,OAAO,EAER,IAAMA,EAAID,EAAKC,EAAIF,EAAKE,IACvB,GAAKL,EAAKK,KAAQJ,EACjB,OAAO,EAGT,OAAO,GC/DR7C,GALeL,GCrBX8B,GAAW9B,EAAsC2B,YA0BrD,ICTAtB,GDDA,SAAoBoD,GACnB,IAAM3B,GAAU2B,GACf,MAAM,IAAIjE,UAAW,8DAA8DiE,EAAI,MAExF,OAAOA,EAAIC,eEpBR5B,GAAW9B,EAAsC2B,YA0BrD,ICTAtB,GDDA,SAAoBoD,GACnB,IAAM3B,GAAU2B,GACf,MAAM,IAAIjE,UAAW,8DAA8DiE,EAAI,MAExF,OAAOA,EAAIE,eEpBRC,GAAY5D,GACZ6D,GAAY/D,GACZgC,GAAW/B,EAAsC4B,YAsCrD,ICpBAtB,GDSA,SAAsBX,GACrB,OACCoC,GAAUpC,IACVA,IAAUmE,GAAWnE,IACrBA,IAAUkE,GAAWlE,IEjCnB+C,GAAOzC,GACP0C,GAAO5C,GAyCX,IChBAO,GDEA,SAAmB6B,GAClB,OAECA,GAAMA,GAGNA,EAAIQ,IACJR,EAAIO,IEnCFN,GAAYnC,GAAuC2B,YA6BvD,IAAArB,GAVA,SAA+BZ,GAC9B,OACCyC,GAAWzC,IACXA,GAAS,GCtBPyC,GAAYnC,GAAuC4B,SA6BvD,IAAAF,GAVA,SAA+BhC,GAC9B,OACCyC,GAAWzC,IACXA,EAAM4B,WAAa,GCtBjBK,GAAc3B,GACd4B,GAAW9B,GAsCf,ICGI+B,GAAc7B,EACd8D,GDXJ,SAA+BpE,GAC9B,OAASiC,GAAajC,IAAWkC,GAAUlC,ICYxCkC,GAAWG,GAKfF,GAAaiC,GAAsB,cANjB/D,IAOlB8B,GAAaiC,GAAsB,WAAYlC,IAK/C,ICxDIkC,GDwDaA,GCxD6DnC,YAC1EG,GAAWhC,EAAsC6B,YAwGrD,IClFAtB,GD6CA,SAAiBoD,EAAKM,GACrB,IAAIC,EACAC,EACJ,IAAMnC,GAAU2B,GACf,MAAM,IAAIjE,UAAW,8DAAgEiE,EAAM,MAE5F,IAAMK,GAAsBC,GAC3B,MAAM,IAAIvE,UAAW,4EAA8EuE,EAAI,MAExG,GAAoB,IAAfN,EAAIrB,QAAsB,IAAN2B,EACxB,MAAO,GAGR,GAAKN,EAAIrB,OAAS2B,EEpDY,iBFqD7B,MAAM,IAAIG,WAAY,iFAIvB,IAFAF,EAAM,GACNC,EAAMF,EAGY,IAAP,EAAJE,KACLD,GAAOP,GAIK,KADbQ,KAAS,IAKTR,GAAOA,EAER,OAAOO,GGnGJ7B,GAAYnC,GAAuC2B,YACnDG,GAAWhC,EAAsC6B,YAiFrD,IAAAwC,GAzCA,SAAqBV,EAAKW,EAAQjB,GACjC,IAAIE,EACAC,EACJ,IAAMxB,GAAU2B,GACf,MAAM,IAAIjE,UAAW,wEAA0EiE,EAAM,MAEtG,IAAM3B,GAAUsC,GACf,MAAM,IAAI5E,UAAW,yEAA2E4E,EAAS,MAE1G,GAAKb,UAAUnB,OAAS,EAAI,CAC3B,IAAMD,GAAWgB,GAChB,MAAM,IAAI3D,UAAW,gEAAkE2D,EAAW,MAGlGE,EADIF,EAAW,EACTM,EAAIrB,OAASe,EAEbA,OAGPE,EAAM,EAEP,GAAuB,IAAlBe,EAAOhC,OACX,OAAO,EAER,GACCiB,EAAM,GACNA,EAAMe,EAAOhC,OAASqB,EAAIrB,OAE1B,OAAO,EAER,IAAMkB,EAAI,EAAGA,EAAIc,EAAOhC,OAAQkB,IAC/B,GAAKG,EAAIY,WAAYhB,EAAMC,KAAQc,EAAOC,WAAYf,GACrD,OAAO,EAGT,OAAO,GC5EJgB,GAAStE,GACTuE,GCqBavE,GDejB,IAAAwE,GAtBA,SAAkBf,EAAKgB,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQhB,EAAIrB,OACtB,OAAKwC,EAAM,IAGNL,GAAYd,EAAK,OACrBkB,GAAW,EACXlB,EAAMA,EAAIoB,OAAQ,IAEnBpB,EAAM,EACLA,EAAMa,GAAQ,IAAKM,GACnBN,GAAQ,IAAKM,GAAQnB,EACjBkB,IACJlB,EAAM,IAAMA,IAVLA,GEnBLqB,GAAc9E,GACd6D,GAAY/D,GACZ8D,GAAY7D,GACZgF,GAAWhD,GACXO,GAAW0C,GAAsCrD,YACjDsD,GAAUC,GAuFd,IAAAC,GA1EA,SAAwBC,GACvB,IAAIC,EACAhE,EACAiC,EAEJ,OAAS8B,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAhE,EAAM+D,EAAMG,IACZjC,EAAIkC,SAAUnE,EAAK,KACb0D,GAAUzB,GAAM,CACrB,IAAMhB,GAAUjB,GACf,MAAM,IAAI1B,MAAO,2BAA6B0B,GAE/CiC,EAAI,EAmCL,OAjCKA,EAAI,IAA2B,MAApB8B,EAAME,WAA8B,KAATD,KAC1C/B,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRjC,IAASiC,GAAI/E,SAAU8G,GAClBD,EAAMK,YACVpE,EAAM4D,GAAS5D,EAAK+D,EAAMK,UAAWL,EAAMM,WAE5CrE,EAAM,IAAMA,IAEZA,EAAMiC,EAAE/E,SAAU8G,GACZ/B,GAAM8B,EAAMK,UAENL,EAAMK,YACjBpE,EAAM4D,GAAS5D,EAAK+D,EAAMK,UAAWL,EAAMM,WAF3CrE,EAAM,GAIF+D,EAAMO,OACVtE,EAAM+D,EAAMO,KAAOtE,IAGP,KAATgE,IACCD,EAAMQ,YACVvE,EAAM,KAAOA,GAEdA,EAAQyD,GAAaM,EAAME,WAC1BzB,GAAWxC,GACXuC,GAAWvC,IAEC,IAATgE,GACCD,EAAMQ,WAAiC,MAApBvE,EAAIwE,OAAQ,KACnCxE,EAAM,IAAMA,GAGPA,GCtFJS,GAAW9B,EAAsC2B,YAKjDmE,GAAW,yBAqDf,ICzCAzF,GDIA,SAAkBoD,GACjB,IACIsC,EACAzC,EAEJ,IAAMxB,GAAU2B,GACf,MAAM,IAAIjE,UAAW,uEAAyEiE,EAAM,MAGrG,GAAkB,MAAbA,EAAK,GAGT,IAAMH,EADAG,EAAIrB,OACI,EAAGkB,GAAK,GACH,MAAbG,EAAKH,GADcA,KAO1B,YAAW,IAANA,GAAgBA,GAAK,EAClBG,EAAIuC,QAASF,GAAU,SAM/BC,GAHAA,EAAItC,EAAIwC,UAAW,EAAG3C,IAGhB0C,QAASF,GAAU,QAGzBrC,EAAMA,EAAK,GAAMsC,EAAItC,EAAIwC,UAAW3C,KE/CrC4C,GALS,ICyBT,IAAA5F,GAPA,SAAoBZ,GACnB,MAA0B,kBAAVA,GCjBbnB,GCDW4H,QAAQ9H,UAAUE,SDyBjC,IEvBIiD,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADAnB,GAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBP,IA0CrB,IAAA0B,GAhBA,SAAoBhC,GACnB,MAAsB,iBAAVA,IACNA,aAAiByG,UAGjB5F,GACGkB,GAAM/B,GAEoB,qBAAzB8B,GAAa9B,MClCpBiC,GAAc3B,GACd4B,GAAW9B,GAkCf,ICAI+B,GAAc7B,EACdoG,GDRJ,SAAoB1G,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICSxCkC,GAAWG,GAKfF,GAAauE,GAAW,cANNrG,IAOlB8B,GAAauE,GAAW,WAAYxE,IAKpC,IAAAvB,GAAiB+F,GCpCjB,IAAAC,GAPA,WACC,OAAO,IAAIC,SAAU,eAAd,ICFRC,GAL4B,iBAATC,KAAsBA,KAAO,KCKhDC,GAL8B,iBAAXC,OAAwBA,OAAS,6GCAhDzH,GAA0B,iBAAX0H,GAAwBA,GAAS,KAKpDC,OAAOC,QAAU5H,OCLbmH,GAAYpG,GAAuC2B,YACnDmF,GAAUhH,GACViH,GAAOhH,GACPiH,GAAMjF,GACNkF,sCAkDJ,IAAAhH,GA7BA,SAAoBoG,GACnB,GAAK9C,UAAUnB,OAAS,CACvB,IAAMgE,GAAWC,GAChB,MAAM,IAAI7G,UAAW,+DAA+D6G,EAAQ,MAE7F,GAAKA,EACJ,OAAOS,KAKT,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,MAAM,IAAItH,MAAO,uDC3CduH,GCOYlH,KDNZmH,GAAWD,GAAKE,UAAYF,GAAKE,SAASC,WER1CC,GAAaC,UCEbC,GAAKxH,GACLmH,GHUaA,GGTbG,GDCaA,GC6BjB,IAAAG,GAnBA,WACC,MAEe,mBAAPD,IAGe,iBAAfF,IAGa,mBAAbH,ICST,IAAAlH,GAPA,WACC,MAAO,2BCEJyH,GAAiB5H,GADHE,EAOL0H,GAAgB,SCjCR1H,MDsCrB,IAAAK,GAAiBqH,GEtCblG,GAAcxB,EAwClB,ICxCI2H,GD+BCC,MAAMD,QACNC,MAAMD,QARX,SAAkBjI,GACjB,MAAkC,mBAAzB8B,GAAa9B,IECvB,ICGImI,GDbJ,SAAuBnI,GACtB,OACW,OAAVA,GACiB,iBAAVA,GCQSM,EAOL6H,GAAc,oBFR3B,SAAmBC,GAClB,GAA0B,mBAAdA,EACX,MAAM,IAAItI,UAAW,sDAAwDsI,EAAY,MAE1F,OASA,SAAgBpI,GACf,IAAI0D,EACAE,EACJ,IAAMqE,GAASjI,GACd,OAAO,EAGR,GAAa,KADb0D,EAAM1D,EAAM0C,QAEX,OAAO,EAER,IAAMkB,EAAI,EAAGA,EAAIF,EAAKE,IACrB,IAAiC,IAA5BwE,EAAWpI,EAAO4D,IACtB,OAAO,EAGT,OAAO,GEpBuCyE,CAAUF,KAK1D,ICvCIA,GDuCaA,GCQjB,IC/CIrG,GAAcxB,EACdwH,GAAK1H,GAA0CkI,OAC/CC,GDyBJ,SAAmBvI,GAClB,OACCmI,GAAcnI,KAGbA,EAAMwI,WAELxI,EAAMyI,aAGgC,mBAA/BzI,EAAMyI,YAAYF,UACzBvI,EAAMyI,YAAYF,SAAUvI,KCmBhC,IAAAO,GAxBA,SAA0BY,GACzB,IAAIuH,EACAC,EACAC,EAEJ,IAAe,YADfD,EAAO7G,GAAaX,GAAI0H,MAAO,GAAI,KACC,UAATF,IAAqBxH,EAAEsH,YAAc,CAE/D,GAA0B,iBAD1BG,EAAOzH,EAAEsH,aACQE,KAChB,OAAOC,EAAKD,KAGb,GADAD,EAAQZ,GAAGgB,KAAMF,EAAK/J,YAErB,OAAO6J,EAAO,GAGhB,OAAKH,GAAUpH,GACP,SAEDwH,GCnDJI,GCkBkBzI,GDmCtB,IErDIyI,GDkBkBzI,GCAtB,ICFI0I,GHkBJ,SAAiB7H,GAChB,IAAI8H,EAGJ,OAAW,OAAN9H,EACG,OAKM,YAHd8H,SAAc9H,GAIN4H,GAAU5H,GAAI6C,cAEfiF,GG9BJ3J,GDNJ,SAAiB6B,GAChB,OAAO4H,GAAU5H,GAAI6C,eEZlBgF,GDec1I,KAOahB,GAAW0J,GCK1C,ICNArI,GDFA,SAAqBX,GAEpB,MAA6B,aAApBgJ,GAAQhJ,IErBd8I,GCFOI,OAAOvK,UAAUmK,KD0B5B,IEvBIhH,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADA8I,GAAKjJ,KAAMG,IACJ,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBP,IA0CrB,IC1CI6I,GAAU7I,GACV8I,GAAahJ,GACbgC,GAAW/B,EAAsC4B,YACjDoH,GDuBJ,SAAmBrJ,GAClB,MAAsB,iBAAVA,IACNA,aAAiBkJ,SAGjBrI,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MEDxB,ICjCIoF,GAAc9E,GACd6D,GAAY/D,GACZ8D,GAAY7D,GACZiG,GFsCJ,SAAkBvC,EAAKW,EAAQ4E,GAC9B,IAAMlH,GAAU2B,GACf,MAAM,IAAIjE,UAAW,wEAA0EiE,EAAM,MAEtG,GAAK3B,GAAUsC,GACdA,EAASyE,GAASzE,GAClBA,EAAS,IAAIwE,OAAQxE,EAAQ,UAEzB,IAAM2E,GAAU3E,GACpB,MAAM,IAAI5E,UAAW,+FAAiG4E,EAAS,MAEhI,IAAMtC,GAAUkH,KAAaF,GAAYE,GACxC,MAAM,IAAIxJ,UAAW,gGAAkGwJ,EAAS,MAEjI,OAAOvF,EAAIuC,QAAS5B,EAAQ4E,IEnDzBjE,GAAWC,GACX1C,GAAW4C,GAAsCvD,YACjDsH,GDoBJ,SAAc/G,GACb,OAAOD,KAAKgH,IAAK/G,IChBdgH,GAAoB,WACpBC,GAAoB,UACpBC,GAAiB,UACjBC,GAAuB,UACvBC,GAA0B,OAC1BC,GAAqB,QACrBC,GAAqB,gBAuEzB,IAAAC,GA1DA,SAAuBrE,GACtB,IAAIsE,EACArI,EACAsI,EAAIC,WAAYxE,EAAMG,KAC1B,IAAMR,GAAU4E,GAAM,CACrB,IAAMrH,GAAU8C,EAAMG,KACrB,MAAM,IAAI5F,MAAO,yCAA2C0B,GAG7DsI,EAAIvE,EAAMG,IAEX,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJjE,EAAMsI,EAAEE,cAAezE,EAAMK,WAC7B,MACD,IAAK,IACL,IAAK,IACJpE,EAAMsI,EAAEG,QAAS1E,EAAMK,WACvB,MACD,IAAK,IACL,IAAK,IACCwD,GAAKU,GAAM,OACfD,EAAStE,EAAMK,WACD,IACbiE,GAAU,GAEXrI,EAAMsI,EAAEE,cAAeH,IAEvBrI,EAAMsI,EAAEI,YAAa3E,EAAMK,WAEtBL,EAAMQ,YACXvE,EAAM2E,GAAS3E,EAAKmI,GAAoB,OACxCnI,EAAM2E,GAAS3E,EAAKkI,GAAoB,KACxClI,EAAM2E,GAAS3E,EAAKiI,GAAyB,KAE9C,MACD,QACC,MAAM,IAAI3J,MAAO,mCAAqCyF,EAAME,WAc7D,OAZAjE,EAAM2E,GAAS3E,EAAK6H,GAAmB,SACvC7H,EAAM2E,GAAS3E,EAAK8H,GAAmB,SAClC/D,EAAMQ,YACVvE,EAAM2E,GAAS3E,EAAK+H,GAAgB,OACpC/H,EAAM2E,GAAS3E,EAAKgI,GAAsB,SAEtCM,GAAK,GAAKvE,EAAMO,OACpBtE,EAAM+D,EAAMO,KAAOtE,GAEpBA,EAAQyD,GAAaM,EAAME,WAC1BzB,GAAWxC,GACXuC,GAAWvC,ICjFTmG,GAAK,6EA8DT,IC9DIlD,GAAStE,GA4Bb,IC5BI8B,GAAW9B,EAAsC2B,YACjDqI,GAAWlK,GACXgD,GAAQ/C,GACRkK,GAAgBlI,GAChBmI,GAAelF,GACfmF,GFOJ,SAAmB1G,GAClB,IAAI2G,EACAC,EACAC,EACAC,EACAnC,EAKJ,IAHAgC,EAAY,EACZE,EAAS,GACTlC,EAAQZ,GAAGgB,KAAM/E,GACT2E,IACPiC,EAAU5G,EAAI8E,MAAO6B,EAAW5C,GAAG4C,UAAYhC,EAAO,GAAIhG,SAC7CA,QACZkI,EAAOE,KAAMH,IAEdE,EAASE,EAAOrC,EAAOkC,EAAOlI,UAE7BkI,EAAOE,KAAMD,GAEdH,EAAY5C,GAAG4C,UACfhC,EAAQZ,GAAGgB,KAAM/E,GAMlB,OAJA4G,EAAU5G,EAAI8E,MAAO6B,IACRhI,QACZkI,EAAOE,KAAMH,GAEPC,EASP,SAASG,EAAOrC,GACf,MAAO,CACNsC,QAAatC,EAAO,GAAQ5C,SAAU4C,EAAO,GAAK,SAAO,EACzDuC,MAASvC,EAAO,GAChB3D,MAAS2D,EAAO,GAChBwC,UAA4B,MAAfxC,EAAO,GACpB3C,UAAa2C,EAAO,GACpB9C,UAAa8C,EAAO,MEhDnByC,GDQJ,SAAmBpH,EAAKgB,EAAOC,GAC9B,IAAIE,EAAMH,EAAQhB,EAAIrB,OACtB,OAAKwC,EAAM,EACHnB,EAERA,EAAM,EACLA,EAAMa,GAAQ,IAAKM,GACnBN,GAAQ,IAAKM,GAAQnB,GCdnBwB,GAAU6F,GAKVC,GAAexJ,OAAOwJ,aA+J1B,IAAA9K,GAzIA,SAAiBwD,GAChB,IAAI6G,EACAK,EACAvF,EACA4F,EACAC,EACA5J,EACAgC,EACAC,EACA4H,EAEJ,IAAMpJ,GAAU2B,GACf,MAAM,IAAIjE,UAAW,oDAAsDiE,EAAM,MAKlF,IAHA6G,EAASH,GAAU1G,GACnBpC,EAAM,GACNgC,EAAM,EACAC,EAAI,EAAGA,EAAIgH,EAAOlI,OAAQkB,IAE/B,GADA8B,EAAQkF,EAAQhH,GACXxB,GAAUsD,GACd/D,GAAO+D,MAEH,CAKJ,IAJKA,EAAMsF,UACVrH,EAAM+B,EAAMsF,SAEbC,EAAQvF,EAAMuF,MACRO,EAAI,EAAGA,EAAIP,EAAMvI,OAAQ8I,IAE9B,OADAF,EAAOL,EAAM9E,OAAQqF,IAErB,IAAK,IACJ9F,EAAMO,KAAO,IACb,MACD,IAAK,IACJP,EAAMO,KAAO,IACb,MACD,IAAK,IACJP,EAAMM,UAAW,EACjBN,EAAM+F,UAAW,EACjB,MACD,IAAK,IACJ/F,EAAM+F,UAAYnB,GAAUW,EAAO,KACnC,MACD,IAAK,IACJvF,EAAMQ,WAAY,EAClB,MACD,QACC,MAAM,IAAIjG,MAAO,iBAAmBqL,GAGtC,GAAqB,MAAhB5F,EAAMX,MAAgB,CAG1B,GAFAW,EAAMX,MAAQe,SAAUjC,UAAWF,GAAO,IAC1CA,GAAO,EACFP,GAAOsC,EAAMX,OACjB,MAAM,IAAIjF,UAAW,wCAA0C6D,EAAM,6BAA+B+B,EAAMX,MAAQ,MAE9GW,EAAMX,MAAQ,IAClBW,EAAMM,UAAW,EACjBN,EAAMX,OAASW,EAAMX,OAGvB,GAAyB,MAApBW,EAAMK,WAAqBL,EAAMwF,UAAY,CAGjD,GAFAxF,EAAMK,UAAYD,SAAUjC,UAAWF,GAAO,IAC9CA,GAAO,EACFP,GAAOsC,EAAMK,WACjB,MAAM,IAAIjG,UAAW,4CAA8C6D,EAAM,6BAA+B+B,EAAMK,UAAY,MAEtHL,EAAMK,UAAY,IACtBL,EAAMK,UAAY,EAClBL,EAAMwF,WAAY,GAIpB,OADAxF,EAAMG,IAAMhC,UAAWF,GACd+B,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAECF,EAAMwF,YACVxF,EAAM+F,UAAW,GAElB/F,EAAMG,IAAM0E,GAAe7E,GAC3B,MACD,IAAK,IAEJA,EAAMgG,SAAahG,EAAe,UAAKA,EAAMK,WAAa,EAC1D,MACD,IAAK,IAEJ,IAAM3C,GAAOsC,EAAMG,KAAQ,CAE1B,IADA0F,EAAMzF,SAAUJ,EAAMG,IAAK,KAChB,GAAK0F,EAAM,IACrB,MAAM,IAAItL,MAAO,kCAAoCyF,EAAMG,KAE5DH,EAAMG,IAAQzC,GAAOmI,GACpB1J,OAAQ6D,EAAMG,KACdwF,GAAcE,GAEhB,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEE7F,EAAMwF,YACXxF,EAAMK,UAAY,GAEnBL,EAAMG,IAAM2E,GAAc9E,GAC1B,MACD,QACC,MAAM,IAAIzF,MAAO,sBAAwByF,EAAME,WAG3CF,EAAMgG,UAAY,GAAKhG,EAAMG,IAAInD,OAASgD,EAAMgG,WACpDhG,EAAMG,IAAMH,EAAMG,IAAIU,UAAW,EAAGb,EAAMgG,WAEtChG,EAAM+F,SACV/F,EAAMG,IAAMN,GAASG,EAAMG,IAAKH,EAAMX,OAASW,EAAMK,UAAWL,EAAMM,UAC3DN,EAAMX,QACjBW,EAAMG,IAAMsF,GAAUzF,EAAMG,IAAKH,EAAMX,MAAOW,EAAMM,WAErDrE,GAAO+D,EAAMG,KAAO,GACpBlC,GAAO,EAGT,OAAOhC,GCrKJgK,GCeSrL,GD0Jb,IAAAC,GAhEA,WACC,IAAIqL,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/F,EACAmF,EACA5H,EASJ,IANAgI,EAAU/H,UAAW,GACrBgI,EAAShI,UAAW,GAGpBiI,GADAG,EAAQpI,UAAW,GADnBmI,GAHAD,EAAQlI,UAAW,IAGLnB,UAECA,OACfyJ,EAAMN,EACAjI,EAAI,EAAGA,EAAIoI,EAAOpI,IAAM,CAI7B,GAHAwI,EAAIL,EAAOnI,GACX4H,EAAI3H,UAAWD,EAAE,GAEH,WADdsI,EAAOD,EAAOrI,EAAEkI,IAEVN,EAAI,EACRA,EAAI,EACOA,GAAKY,IAChBZ,EAAIY,EAAI,QAEH,GAAc,SAATF,EACNV,EAAI,GACRA,GAAKY,GACI,GAEG,KADXZ,GAAKY,KAEJZ,GAAKY,GAGIZ,GAAKY,IAChBZ,GAAKY,IACKA,IACTZ,GAAKY,QAGD,GAAKZ,EAAI,GAAKA,GAAKY,EACzB,MAAM,IAAI5H,WAAYmH,GAAQ,6FAA8F/H,EAAG4H,KAEhInF,EAAIuF,EAAShI,IAGJ,GAAgB,IAAXiI,EACbM,GAAOX,EAAInF,EAEX8F,GAAOX,EAAInF,EAGb,OAAO8F,UElJM7L"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..778fc68 --- /dev/null +++ b/package.json @@ -0,0 +1,41 @@ +{ + "name": "@stdlib/ndarray-base-sub2ind", + "version": "0.0.0", + "description": "Convert subscripts to a linear index.", + "license": "Apache-2.0", + "main": "./bundle.js", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/ndarray-base-sub2ind.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdtypes", + "types", + "base", + "ndarray", + "shape", + "strides", + "offset", + "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..4c4dfff --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 6154dd1040d330a6b2b7bf5418e1655ac1653cfc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 21:27:14 +0000 Subject: [PATCH 002/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index bc49a2b..be5ab40 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From 11dd96717238aa195b8d6e53a379c673842fba6d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 11:18:51 +0000 Subject: [PATCH 003/140] Remove files --- bundle.js | 3 - bundle.js.map | 1 - stats.html | 2689 ------------------------------------------------- 3 files changed, 2693 deletions(-) delete mode 100644 bundle.js delete mode 100644 bundle.js.map delete mode 100644 stats.html diff --git a/bundle.js b/bundle.js deleted file mode 100644 index 8143d77..0000000 --- a/bundle.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(r="undefined"!=typeof globalThis?globalThis:r||self).sub2ind=e()}(this,(function(){"use strict";function r(r){if(r.__esModule)return r;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(r).forEach((function(t){var n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:function(){return r[t]}})})),e}var e="function"==typeof Object.defineProperty?Object.defineProperty:null;var t=function(){try{return e({},"x",{}),!0}catch(r){return!1}},n=Object.defineProperty,i=Object.prototype,a=i.toString,o=i.__defineGetter__,u=i.__defineSetter__,c=i.__lookupGetter__,s=i.__lookupSetter__;var f=function(r,e,t){var n,f,l,p;if("object"!=typeof r||null===r||"[object Array]"===a.call(r))throw new TypeError("invalid argument. First argument must be an object. Value: `"+r+"`.");if("object"!=typeof t||null===t||"[object Array]"===a.call(t))throw new TypeError("invalid argument. Property descriptor must be an object. Value: `"+t+"`.");if((f="value"in t)&&(c.call(r,e)||s.call(r,e)?(n=r.__proto__,r.__proto__=i,delete r[e],r[e]=t.value,r.__proto__=n):r[e]=t.value),l="get"in t,p="set"in t,f&&(l||p))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return l&&o&&o.call(r,e,t.get),p&&u&&u.call(r,e,t.set),r},l=n,p=f,v=t()?l:p;var g=function(r,e,t){v(r,e,{configurable:!1,enumerable:!1,writable:!1,value:t})},d=g;var h=function(r){return"string"==typeof r};var m=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var b=function(){return m&&"symbol"==typeof Symbol.toStringTag},w=Object.prototype.toString,y=w;var E=function(r){return y.call(r)},j=Object.prototype.hasOwnProperty;var P=function(r,e){return null!=r&&j.call(r,e)},_="function"==typeof Symbol?Symbol.toStringTag:"",T=P,x=_,O=w;var S=E,V=function(r){var e,t,n;if(null==r)return O.call(r);t=r[x],e=T(r,x);try{r[x]=void 0}catch(e){return O.call(r)}return n=O.call(r),e?r[x]=t:delete r[x],n},k=b()?V:S,I=String.prototype.valueOf;var A=k,R=function(r){try{return I.call(r),!0}catch(r){return!1}},$=b();var F=function(r){return"object"==typeof r&&(r instanceof String||($?R(r):"[object String]"===A(r)))},M=h,C=F;var N=d,B=function(r){return M(r)||C(r)},G=F;N(B,"isPrimitive",h),N(B,"isObject",G);var L=B,Z=Math.floor;var W=function(r){return Z(r)===r},X=W;var z=function(r){return"object"==typeof r&&null!==r&&"number"==typeof r.length&&X(r.length)&&r.length>=0&&r.length<=9007199254740991};var U=function(r){return"number"==typeof r},Y=Number,D=Y.prototype.toString;var q=k,H=Y,J=function(r){try{return D.call(r),!0}catch(r){return!1}},K=b();var Q=function(r){return"object"==typeof r&&(r instanceof H||(K?J(r):"[object Number]"===q(r)))},rr=U,er=Q;var tr=d,nr=function(r){return rr(r)||er(r)},ir=Q;tr(nr,"isPrimitive",U),tr(nr,"isObject",ir);var ar=nr,or=Number.POSITIVE_INFINITY,ur=Y.NEGATIVE_INFINITY,cr=or,sr=ur,fr=W;var lr=function(r){return rsr&&fr(r)},pr=ar.isPrimitive,vr=lr;var gr=function(r){return pr(r)&&vr(r)},dr=ar.isObject,hr=lr;var mr=function(r){return dr(r)&&hr(r.valueOf())},br=gr,wr=mr;var yr=d,Er=function(r){return br(r)||wr(r)},jr=mr;yr(Er,"isPrimitive",gr),yr(Er,"isObject",jr);var Pr=Er;var _r=function(r){return r!=r},Tr=ar.isPrimitive,xr=_r;var Or=function(r){return Tr(r)&&xr(r)},Sr=ar.isObject,Vr=_r;var kr=function(r){return Sr(r)&&Vr(r.valueOf())},Ir=Or,Ar=kr;var Rr=d,$r=function(r){return Ir(r)||Ar(r)},Fr=kr;Rr($r,"isPrimitive",Or),Rr($r,"isObject",Fr);var Mr=z,Cr=Pr.isPrimitive,Nr=L.isPrimitive,Br=$r.isPrimitive;var Gr=function(r,e,t){var n,i,a;if(!Mr(r)&&!Nr(r))throw new TypeError("invalid argument. First argument must be array-like. Value: `"+r+"`.");if(arguments.length<2)throw new Error("insufficient input arguments. Must provide a search value.");if(arguments.length>2){if(!Cr(t))throw new TypeError("invalid argument. Third argument must be an integer. Value: `"+t+"`.");(i=t)<0&&(i=0)}else i=0;if(Nr(r)){if(!Nr(e))throw new TypeError("invalid argument. Second argument must be a string primitive. Value: `"+e+"`.");return-1!==r.indexOf(e,i)}if(n=r.length,Br(e)){for(a=i;aJr&&r=0},ee=Pr.isObject;var te=function(r){return ee(r)&&r.valueOf()>=0},ne=re,ie=te;var ae=d,oe=function(r){return ne(r)||ie(r)},ue=te;ae(oe,"isPrimitive",re),ae(oe,"isObject",ue);var ce=oe.isPrimitive,se=L.isPrimitive;var fe=function(r,e){var t,n;if(!se(r))throw new TypeError("invalid argument. First argument must be a string. Value: `"+r+"`.");if(!ce(e))throw new TypeError("invalid argument. Second argument must be a nonnegative integer. Value: `"+e+"`.");if(0===r.length||0===e)return"";if(r.length*e>9007199254740991)throw new RangeError("invalid argument. Output string length exceeds maximum allowed string length.");for(t="",n=e;1==(1&n)&&(t+=r),0!==(n>>>=1);)r+=r;return t},le=Pr.isPrimitive,pe=L.isPrimitive;var ve=function(r,e,t){var n,i;if(!pe(r))throw new TypeError("invalid argument. First argument must be a string primitive. Value: `"+r+"`.");if(!pe(e))throw new TypeError("invalid argument. Second argument must be a string primitive. Value: `"+e+"`.");if(arguments.length>2){if(!le(t))throw new TypeError("invalid argument. Third argument must be an integer. Value: `"+t+"`.");n=t<0?r.length+t:t}else n=0;if(0===e.length)return!0;if(n<0||n+e.length>r.length)return!1;for(i=0;i=0&&"/"!==r[t];t--);return void 0===t||t<=0?r.replace(Te,"\\$&"):(e=(e=r.substring(1,t)).replace(Te,"\\$&"),r=r[0]+e+r.substring(t))},Oe=/./;var Se=function(r){return"boolean"==typeof r},Ve=Boolean.prototype.toString;var ke=k,Ie=function(r){try{return Ve.call(r),!0}catch(r){return!1}},Ae=b();var Re=function(r){return"object"==typeof r&&(r instanceof Boolean||(Ae?Ie(r):"[object Boolean]"===ke(r)))},$e=Se,Fe=Re;var Me=d,Ce=function(r){return $e(r)||Fe(r)},Ne=Re;Me(Ce,"isPrimitive",Se),Me(Ce,"isObject",Ne);var Be=Ce;var Ge=function(){return new Function("return this;")()},Le="object"==typeof self?self:null,Ze="object"==typeof window?window:null,We="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},Xe="object"==typeof We?We:null;module.exports=Xe;var ze=Be.isPrimitive,Ue=Ge,Ye=Le,De=Ze,qe=r(Object.freeze({__proto__:null}));var He=function(r){if(arguments.length){if(!ze(r))throw new TypeError("invalid argument. Must provide a boolean primitive. Value: `"+r+"`.");if(r)return Ue()}if(Ye)return Ye;if(De)return De;if(qe)return qe;throw new Error("unexpected error. Unable to resolve global object.")},Je=He(),Ke=Je.document&&Je.document.childNodes,Qe=Int8Array,rt=Oe,et=Ke,tt=Qe;var nt=function(){return"function"==typeof rt||"object"==typeof tt||"function"==typeof et};var it=function(){return/^\s*function\s*([^(]*)/i},at=it;d(at,"REGEXP",it());var ot=at,ut=k;var ct=Array.isArray?Array.isArray:function(r){return"[object Array]"===ut(r)};var st=function(r){return null!==r&&"object"==typeof r};d(st,"isObjectLikeArray",function(r){if("function"!=typeof r)throw new TypeError("invalid argument. Must provide a function. Value: `"+r+"`.");return function(e){var t,n;if(!ct(e))return!1;if(0===(t=e.length))return!1;for(n=0;n0&&(e-=1),t=n.toExponential(e)):t=n.toPrecision(r.precision),r.alternate||(t=At(t,Zt,"$1e"),t=At(t,Lt,"e"),t=At(t,Gt,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return t=At(t,Mt,"e+0$1"),t=At(t,Ct,"e-0$1"),r.alternate&&(t=At(t,Nt,"$1."),t=At(t,Bt,"$1.e")),n>=0&&r.sign&&(t=r.sign+t),t=Vt(r.specifier)?kt(t):It(t)},Xt=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;var zt=fe;var Ut=L.isPrimitive,Yt=Lr,Dt=_r,qt=Pe,Ht=Wt,Jt=function(r){var e,t,n,i,a;for(e=0,n=[],a=Xt.exec(r);a;)(t=r.slice(e,Xt.lastIndex-a[0].length)).length&&n.push(t),(i=o(a,n.length))&&n.push(i),e=Xt.lastIndex,a=Xt.exec(r);return(t=r.slice(e)).length&&n.push(t),n;function o(r){return{mapping:r[1]?parseInt(r[1],10):void 0,flags:r[2],width:r[3],hasPeriod:"."===r[4],precision:r[5],specifier:r[6]}}},Kt=function(r,e,t){var n=e-r.length;return n<0?r:r=t?r+zt(" ",n):zt(" ",n)+r},Qt=he,rn=String.fromCharCode;var en=function(r){var e,t,n,i,a,o,u,c,s;if(!Ut(r))throw new TypeError("invalid argument. Must provide a string. Value: `"+r+"`.");for(e=Jt(r),o="",u=1,c=0;c127)throw new Error("invalid character code. Value: "+n.arg);n.arg=Dt(a)?String(n.arg):rn(a)}break;case"e":case"E":case"f":case"F":case"g":case"G":n.hasPeriod||(n.precision=6),n.arg=Ht(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=Qt(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=Kt(n.arg,n.width,n.padRight)),o+=n.arg||"",u+=1}return o},tn=en;var nn=function(){var r,e,t,n,i,a,o,u,c,s,f,l;for(r=arguments[1],e=arguments[2],t=(a=arguments[3+(i=(n=arguments[0]).length)]).length,u=e,l=0;l=c&&(f=c-1);else if("wrap"===o)f<0?(f+=c)<0&&0!==(f%=c)&&(f+=c):f>=c&&(f-=c)>=c&&(f%=c);else if(f<0||f>=c)throw new RangeError(tn("invalid argument. Subscripts must not exceed array dimensions. Subscript: %u. Value: `%d`.",l,f));(s=r[l])<0&&0===e?u-=f*s:u+=f*s}return u};return nn})); -//# sourceMappingURL=bundle.js.map diff --git a/bundle.js.map b/bundle.js.map deleted file mode 100644 index aff6364..0000000 --- a/bundle.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"bundle.js","sources":["../node_modules/@stdlib/utils-define-property/lib/define_property.js","../node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js","../node_modules/@stdlib/utils-define-property/lib/builtin.js","../node_modules/@stdlib/utils-define-property/lib/polyfill.js","../node_modules/@stdlib/utils-define-property/lib/index.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/primitive.js","../node_modules/@stdlib/assert-has-symbol-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostring.js","../node_modules/@stdlib/utils-native-class/lib/native_class.js","../node_modules/@stdlib/assert-has-own-property/lib/main.js","../node_modules/@stdlib/assert-has-own-property/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostringtag.js","../node_modules/@stdlib/utils-native-class/lib/polyfill.js","../node_modules/@stdlib/utils-native-class/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/try2valueof.js","../node_modules/@stdlib/assert-is-string/lib/valueof.js","../node_modules/@stdlib/assert-is-string/lib/object.js","../node_modules/@stdlib/assert-is-string/lib/main.js","../node_modules/@stdlib/assert-is-string/lib/index.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/is_integer.js","../node_modules/@stdlib/math-base-special-floor/lib/main.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-collection/lib/main.js","../node_modules/@stdlib/assert-is-collection/lib/index.js","../node_modules/@stdlib/constants-array-max-typed-array-length/lib/index.js","../node_modules/@stdlib/assert-is-number/lib/primitive.js","../node_modules/@stdlib/number-ctor/lib/index.js","../node_modules/@stdlib/number-ctor/lib/number.js","../node_modules/@stdlib/assert-is-number/lib/try2serialize.js","../node_modules/@stdlib/assert-is-number/lib/tostring.js","../node_modules/@stdlib/assert-is-number/lib/object.js","../node_modules/@stdlib/assert-is-number/lib/main.js","../node_modules/@stdlib/assert-is-number/lib/index.js","../node_modules/@stdlib/constants-float64-pinf/lib/index.js","../node_modules/@stdlib/constants-float64-ninf/lib/index.js","../node_modules/@stdlib/assert-is-integer/lib/integer.js","../node_modules/@stdlib/assert-is-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-integer/lib/object.js","../node_modules/@stdlib/assert-is-integer/lib/main.js","../node_modules/@stdlib/assert-is-integer/lib/index.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/main.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-nan/lib/primitive.js","../node_modules/@stdlib/assert-is-nan/lib/object.js","../node_modules/@stdlib/assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-contains/lib/contains.js","../node_modules/@stdlib/assert-contains/lib/index.js","../node_modules/@stdlib/string-lowercase/lib/lowercase.js","../node_modules/@stdlib/string-lowercase/lib/index.js","../node_modules/@stdlib/string-uppercase/lib/uppercase.js","../node_modules/@stdlib/string-uppercase/lib/index.js","../node_modules/@stdlib/assert-is-uppercase/lib/main.js","../node_modules/@stdlib/assert-is-uppercase/lib/index.js","../node_modules/@stdlib/math-base-assert-is-finite/lib/main.js","../node_modules/@stdlib/math-base-assert-is-finite/lib/index.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/object.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/main.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/index.js","../node_modules/@stdlib/string-repeat/lib/repeat.js","../node_modules/@stdlib/string-repeat/lib/index.js","../node_modules/@stdlib/constants-float64-max-safe-integer/lib/index.js","../node_modules/@stdlib/string-starts-with/lib/starts_with.js","../node_modules/@stdlib/string-format/lib/zero_pad.js","../node_modules/@stdlib/string-starts-with/lib/index.js","../node_modules/@stdlib/string-format/lib/format_integer.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/main.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/re.js","../node_modules/@stdlib/assert-is-boolean/lib/primitive.js","../node_modules/@stdlib/assert-is-boolean/lib/try2serialize.js","../node_modules/@stdlib/assert-is-boolean/lib/tostring.js","../node_modules/@stdlib/assert-is-boolean/lib/object.js","../node_modules/@stdlib/assert-is-boolean/lib/main.js","../node_modules/@stdlib/assert-is-boolean/lib/index.js","../node_modules/@stdlib/utils-global/lib/codegen.js","../node_modules/@stdlib/utils-global/lib/self.js","../node_modules/@stdlib/utils-global/lib/window.js","../node_modules/@stdlib/utils-global/lib/global.js","../node_modules/@stdlib/utils-global/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/nodelist.js","../node_modules/@stdlib/utils-global/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/typedarray.js","../node_modules/@stdlib/utils-type-of/lib/check.js","../node_modules/@stdlib/regexp-function-name/lib/main.js","../node_modules/@stdlib/regexp-function-name/lib/index.js","../node_modules/@stdlib/regexp-function-name/lib/regexp.js","../node_modules/@stdlib/assert-is-array/lib/main.js","../node_modules/@stdlib/assert-tools-array-function/lib/arrayfcn.js","../node_modules/@stdlib/assert-is-object-like/lib/main.js","../node_modules/@stdlib/assert-is-object-like/lib/index.js","../node_modules/@stdlib/assert-is-buffer/lib/main.js","../node_modules/@stdlib/utils-constructor-name/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/typeof.js","../node_modules/@stdlib/utils-constructor-name/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/polyfill.js","../node_modules/@stdlib/utils-type-of/lib/index.js","../node_modules/@stdlib/assert-is-function/lib/main.js","../node_modules/@stdlib/assert-is-function/lib/index.js","../node_modules/@stdlib/assert-is-regexp/lib/try2exec.js","../node_modules/@stdlib/assert-is-regexp/lib/exec.js","../node_modules/@stdlib/assert-is-regexp/lib/main.js","../node_modules/@stdlib/string-replace/lib/replace.js","../node_modules/@stdlib/math-base-special-abs/lib/main.js","../node_modules/@stdlib/string-format/lib/format_double.js","../node_modules/@stdlib/string-format/lib/tokenize.js","../node_modules/@stdlib/string-format/lib/space_pad.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js","../node_modules/@stdlib/string-format/lib/index.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\nvar main = ( typeof Object.defineProperty === 'function' ) ? Object.defineProperty : null;\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar defineProperty = require( './define_property.js' );\n\n\n// MAIN //\n\n/**\n* Tests for `Object.defineProperty` support.\n*\n* @private\n* @returns {boolean} boolean indicating if an environment has `Object.defineProperty` support\n*\n* @example\n* var bool = hasDefinePropertySupport();\n* // returns \n*/\nfunction hasDefinePropertySupport() {\n\t// Test basic support...\n\ttry {\n\t\tdefineProperty( {}, 'x', {} );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasDefinePropertySupport;\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// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @name defineProperty\n* @type {Function}\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nvar defineProperty = Object.defineProperty;\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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/* eslint-disable no-underscore-dangle, no-proto */\n\n'use strict';\n\n// VARIABLES //\n\nvar objectProtoype = Object.prototype;\nvar toStr = objectProtoype.toString;\nvar defineGetter = objectProtoype.__defineGetter__;\nvar defineSetter = objectProtoype.__defineSetter__;\nvar lookupGetter = objectProtoype.__lookupGetter__;\nvar lookupSetter = objectProtoype.__lookupSetter__;\n\n\n// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @param {Object} obj - object on which to define the property\n* @param {string} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nfunction defineProperty( obj, prop, descriptor ) {\n\tvar prototype;\n\tvar hasValue;\n\tvar hasGet;\n\tvar hasSet;\n\n\tif ( typeof obj !== 'object' || obj === null || toStr.call( obj ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an object. Value: `' + obj + '`.' );\n\t}\n\tif ( typeof descriptor !== 'object' || descriptor === null || toStr.call( descriptor ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. Property descriptor must be an object. Value: `' + descriptor + '`.' );\n\t}\n\thasValue = ( 'value' in descriptor );\n\tif ( hasValue ) {\n\t\tif (\n\t\t\tlookupGetter.call( obj, prop ) ||\n\t\t\tlookupSetter.call( obj, prop )\n\t\t) {\n\t\t\t// Override `__proto__` to avoid touching inherited accessors:\n\t\t\tprototype = obj.__proto__;\n\t\t\tobj.__proto__ = objectProtoype;\n\n\t\t\t// Delete property as existing getters/setters prevent assigning value to specified property:\n\t\t\tdelete obj[ prop ];\n\t\t\tobj[ prop ] = descriptor.value;\n\n\t\t\t// Restore original prototype:\n\t\t\tobj.__proto__ = prototype;\n\t\t} else {\n\t\t\tobj[ prop ] = descriptor.value;\n\t\t}\n\t}\n\thasGet = ( 'get' in descriptor );\n\thasSet = ( 'set' in descriptor );\n\n\tif ( hasValue && ( hasGet || hasSet ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.' );\n\t}\n\n\tif ( hasGet && defineGetter ) {\n\t\tdefineGetter.call( obj, prop, descriptor.get );\n\t}\n\tif ( hasSet && defineSetter ) {\n\t\tdefineSetter.call( obj, prop, descriptor.set );\n\t}\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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* Define (or modify) an object property.\n*\n* @module @stdlib/utils-define-property\n*\n* @example\n* var defineProperty = require( '@stdlib/utils-define-property' );\n*\n* var obj = {};\n* defineProperty( obj, 'foo', {\n* 'value': 'bar',\n* 'writable': false,\n* 'configurable': false,\n* 'enumerable': false\n* });\n* obj.foo = 'boop'; // => throws\n*/\n\n// MODULES //\n\nvar hasDefinePropertySupport = require( './has_define_property_support.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar defineProperty;\nif ( hasDefinePropertySupport() ) {\n\tdefineProperty = builtin;\n} else {\n\tdefineProperty = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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\nvar defineProperty = require( '@stdlib/utils-define-property' );\n\n\n// MAIN //\n\n/**\n* Defines a non-enumerable read-only property.\n*\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setNonEnumerableReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Define a non-enumerable read-only property.\n*\n* @module @stdlib/utils-define-nonenumerable-read-only-property\n*\n* @example\n* var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\n*\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\n\n// MODULES //\n\nvar setNonEnumerableReadOnly = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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// MAIN //\n\n/**\n* Tests for native `Symbol` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Symbol` support\n*\n* @example\n* var bool = hasSymbolSupport();\n* // returns \n*/\nfunction hasSymbolSupport() {\n\treturn (\n\t\ttypeof Symbol === 'function' &&\n\t\ttypeof Symbol( 'foo' ) === 'symbol'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasSymbolSupport;\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\nvar hasSymbols = require( '@stdlib/assert-has-symbol-support' );\n\n\n// VARIABLES //\n\nvar FLG = hasSymbols();\n\n\n// MAIN //\n\n/**\n* Tests for native `toStringTag` support.\n*\n* @returns {boolean} boolean indicating if an environment has `toStringTag` support\n*\n* @example\n* var bool = hasToStringTagSupport();\n* // returns \n*/\nfunction hasToStringTagSupport() {\n\treturn ( FLG && typeof Symbol.toStringTag === 'symbol' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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* Test for native `toStringTag` support.\n*\n* @module @stdlib/assert-has-tostringtag-support\n*\n* @example\n* var hasToStringTagSupport = require( '@stdlib/assert-has-tostringtag-support' );\n*\n* var bool = hasToStringTagSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasToStringTagSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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// MAIN //\n\nvar toStr = Object.prototype.toString;\n\n\n// EXPORTS //\n\nmodule.exports = toStr;\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\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification (via the internal property `[[Class]]`) of an object.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\treturn toStr.call( v );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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// FUNCTIONS //\n\nvar has = Object.prototype.hasOwnProperty;\n\n\n// MAIN //\n\n/**\n* Tests if an object has a specified property.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object has a specified property\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'bap' );\n* // returns false\n*/\nfunction hasOwnProp( value, property ) {\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\treturn has.call( value, property );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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* Test whether an object has a specified property.\n*\n* @module @stdlib/assert-has-own-property\n*\n* @example\n* var hasOwnProp = require( '@stdlib/assert-has-own-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* bool = hasOwnProp( beep, 'bop' );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasOwnProp = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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// MAIN //\n\nvar toStrTag = ( typeof Symbol === 'function' ) ? Symbol.toStringTag : '';\n\n\n// EXPORTS //\n\nmodule.exports = toStrTag;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar toStringTag = require( './tostringtag.js' );\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification of an object in environments supporting `Symbol.toStringTag`.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\tvar isOwn;\n\tvar tag;\n\tvar out;\n\n\tif ( v === null || v === void 0 ) {\n\t\treturn toStr.call( v );\n\t}\n\ttag = v[ toStringTag ];\n\tisOwn = hasOwnProp( v, toStringTag );\n\n\t// Attempt to override the `toStringTag` property. For built-ins having a `Symbol.toStringTag` property (e.g., `JSON`, `Math`, etc), the `Symbol.toStringTag` property is read-only (e.g., , so we need to wrap in a `try/catch`.\n\ttry {\n\t\tv[ toStringTag ] = void 0;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn toStr.call( v );\n\t}\n\tout = toStr.call( v );\n\n\tif ( isOwn ) {\n\t\tv[ toStringTag ] = tag;\n\t} else {\n\t\tdelete v[ toStringTag ];\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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* Return a string value indicating a specification defined classification of an object.\n*\n* @module @stdlib/utils-native-class\n*\n* @example\n* var nativeClass = require( '@stdlib/utils-native-class' );\n*\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* function Beep() {\n* return this;\n* }\n* str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\n\n// MODULES //\n\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar builtin = require( './native_class.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar nativeClass;\nif ( hasToStringTag() ) {\n\tnativeClass = polyfill;\n} else {\n\tnativeClass = builtin;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to extract a string value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a string can be extracted\n*/\nfunction test( value ) {\n\ttry {\n\t\tvalueOf.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar valueOf = String.prototype.valueOf; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2valueof.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string object\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns false\n*/\nfunction isString( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof String ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object String]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a string\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*/\nfunction isString( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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* Test if a value is a string.\n*\n* @module @stdlib/assert-is-string\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' );\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 5 );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isObject;\n*\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 'beep' );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isString = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isString, 'isPrimitive', isPrimitive );\nsetReadOnly( isString, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Tests if a finite double-precision floating-point number is an integer.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\treturn (floor(x) === x);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// TODO: implementation (?)\n\n/**\n* Rounds a double-precision floating-point number toward negative infinity.\n*\n* @param {number} x - input value\n* @returns {number} rounded value\n*\n* @example\n* var v = floor( -4.2 );\n* // returns -5.0\n*\n* @example\n* var v = floor( 9.99999 );\n* // returns 9.0\n*\n* @example\n* var v = floor( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = floor( NaN );\n* // returns NaN\n*/\nvar floor = Math.floor; // eslint-disable-line stdlib/no-builtin-math\n\n\n// EXPORTS //\n\nmodule.exports = floor;\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* Test if a finite double-precision floating-point number is an integer.\n*\n* @module @stdlib/math-base-assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/math-base-assert-is-integer' );\n*\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* bool = isInteger( 3.14 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isInteger = require( './is_integer.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a collection.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is a collection\n*\n* @example\n* var bool = isCollection( [] );\n* // returns true\n*\n* @example\n* var bool = isCollection( {} );\n* // returns false\n*/\nfunction isCollection( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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* Test if a value is a collection.\n*\n* @module @stdlib/assert-is-collection\n*\n* @example\n* var isCollection = require( '@stdlib/assert-is-collection' );\n*\n* var bool = isCollection( [] );\n* // returns true\n*\n* bool = isCollection( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isCollection = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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* Maximum length of a typed array.\n*\n* @module @stdlib/constants-array-max-typed-array-length\n*\n* @example\n* var MAX_TYPED_ARRAY_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n* // returns 9007199254740991\n*/\n\n// MAIN //\n\n/**\n* Maximum length of a typed array.\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n*/\nvar MAX_TYPED_ARRAY_LENGTH = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = MAX_TYPED_ARRAY_LENGTH;\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* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Constructor which returns a `Number` object.\n*\n* @module @stdlib/number-ctor\n*\n* @example\n* var Number = require( '@stdlib/number-ctor' );\n*\n* var v = new Number( 10.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar Number = require( './number.js' );\n\n\n// EXPORTS //\n\nmodule.exports = Number;\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// EXPORTS //\n\nmodule.exports = Number; // eslint-disable-line stdlib/require-globals\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Number.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar Number = require( '@stdlib/number-ctor' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\nfunction isNumber( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Number ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Number]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a number\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( null );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Test if a value is a number.\n*\n* @module @stdlib/assert-is-number\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' );\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( null );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isObject;\n*\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNumber, 'isPrimitive', isPrimitive );\nsetReadOnly( isNumber, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Double-precision floating-point positive infinity.\n*\n* @module @stdlib/constants-float64-pinf\n* @type {number}\n*\n* @example\n* var FLOAT64_PINF = require( '@stdlib/constants-float64-pinf' );\n* // returns Infinity\n*/\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point positive infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point positive infinity has the bit sequence\n*\n* ```binarystring\n* 0 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.POSITIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_PINF = Number.POSITIVE_INFINITY; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_PINF;\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* Double-precision floating-point negative infinity.\n*\n* @module @stdlib/constants-float64-ninf\n* @type {number}\n*\n* @example\n* var FLOAT64_NINF = require( '@stdlib/constants-float64-ninf' );\n* // returns -Infinity\n*/\n\n// MODULES //\n\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point negative infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point negative infinity has the bit sequence\n*\n* ```binarystring\n* 1 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.NEGATIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_NINF = Number.NEGATIVE_INFINITY;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_NINF;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar isInt = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests if a number primitive is an integer value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a number primitive is an integer value\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tvalue < PINF &&\n\t\tvalue > NINF &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having an integer value\n*\n* @example\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having an integer value\n*\n* @example\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an integer\n*\n* @example\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isInteger( -3.14 );\n* // returns false\n*\n* @example\n* var bool = isInteger( null );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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* Test if a value is an integer.\n*\n* @module @stdlib/assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/assert-is-integer' );\n*\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isInteger( -3.14 );\n* // returns false\n*\n* bool = isInteger( null );\n* // returns false\n*\n* @example\n* // Use interface to check for integer primitives...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n*\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*\n* @example\n* // Use interface to check for integer objects...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n*\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is `NaN`.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 7.0 );\n* // returns false\n*/\nfunction isnan( x ) {\n\treturn ( x !== x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a double-precision floating-point numeric value is `NaN`.\n*\n* @module @stdlib/math-base-assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/math-base-assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 7.0 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isnan = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a `NaN` number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a `NaN` number primitive\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a value of `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a value of `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( null );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a value is `NaN`.\n*\n* @module @stdlib/assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( null );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isObject;\n*\n* var bool = isnan( NaN );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isnan = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isnan, 'isPrimitive', isPrimitive );\nsetReadOnly( isnan, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if an array-like value contains a search value.\n*\n* @param {(Collection|string)} val - input value\n* @param {*} searchValue - search value\n* @param {integer} [position=0] - position at which to start searching for `searchValue`\n* @throws {TypeError} first argument must be array-like\n* @throws {Error} must provide a search value\n* @throws {TypeError} second argument must be a primitive string primitive when the first argument is a string\n* @throws {TypeError} third argument must be an integer\n* @returns {boolean} boolean indicating whether one value contains another\n*\n* @example\n* var bool = contains( 'last man standing', 'stand' );\n* // returns true\n*\n* @example\n* var bool = contains( [ 1, 2, 3, 4 ], 2 );\n* // returns true\n*\n* @example\n* var bool = contains( 'presidential election', 'president' );\n* // returns true\n*\n* @example\n* var bool = contains( [ NaN, 2, 3, 4 ], NaN );\n* // returns true\n*\n* @example\n* var bool = contains( 'javaScript', 'js' );\n* // returns false\n*\n* @example\n* var bool = contains( [ 1, 2, 3, {} ], {} );\n* // returns false\n*\n* @example\n* var bool = contains( 'Hidden Treasures', '' );\n* // returns true\n*/\nfunction contains( val, searchValue, position ) {\n\tvar len;\n\tvar pos;\n\tvar i;\n\tif ( !isCollection( val ) && !isString( val ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be array-like. Value: `' + val + '`.' );\n\t}\n\tif ( arguments.length < 2 ) {\n\t\tthrow new Error( 'insufficient input arguments. Must provide a search value.' );\n\t}\n\tif ( arguments.length > 2 ) {\n\t\tif ( !isInteger( position ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Third argument must be an integer. Value: `' + position + '`.' );\n\t\t}\n\t\tpos = position;\n\t\tif ( pos < 0 ) {\n\t\t\tpos = 0;\n\t\t}\n\t} else {\n\t\tpos = 0;\n\t}\n\tif ( isString( val ) ) {\n\t\tif ( !isString( searchValue ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive. Value: `' + searchValue + '`.' );\n\t\t}\n\t\treturn val.indexOf( searchValue, pos ) !== -1;\n\t}\n\tlen = val.length;\n\tif ( isnan( searchValue ) ) {\n\t\tfor ( i = pos; i < len; i++ ) {\n\t\t\tif ( isnan( val[ i ] ) ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\tfor ( i = pos; i < len; i++ ) {\n\t\tif ( val[ i ] === searchValue ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = contains;\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* Test if an array-like value contains another value.\n*\n* @module @stdlib/assert-contains\n*\n* @example\n* var contains = require( '@stdlib/assert-contains' );\n*\n* var bool = contains( 'Hello World', 'World' );\n* // returns true\n*\n* bool = contains( 'Hello World', 'world' );\n* // returns false\n*\n* bool = contains( [ 1, 2, 3, 4 ], 2 );\n* // returns true\n*\n* bool = contains( [ NaN, 2, 3, 4 ], NaN );\n* // returns true\n*/\n\n// MODULES //\n\nvar contains = require( './contains.js' );\n\n\n// EXPORTS //\n\nmodule.exports = contains;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Converts a string to lowercase.\n*\n* @param {string} str - string to convert\n* @throws {TypeError} must provide a primitive string\n* @returns {string} lowercase string\n*\n* @example\n* var str = lowercase( 'bEEp' );\n* // returns 'beep'\n*/\nfunction lowercase( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a primitive string. Value: `'+str+'`.' );\n\t}\n\treturn str.toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = lowercase;\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 a string to lowercase.\n*\n* @module @stdlib/string-lowercase\n*\n* @example\n* var lowercase = require( '@stdlib/string-lowercase' );\n*\n* var str = lowercase( 'bEEp' );\n* // returns 'beep'\n*/\n\n// MODULES //\n\nvar lowercase = require( './lowercase.js' );\n\n\n// EXPORTS //\n\nmodule.exports = lowercase;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Converts a string to uppercase.\n*\n* @param {string} str - string to convert\n* @throws {TypeError} must provide a primitive string\n* @returns {string} uppercase string\n*\n* @example\n* var str = uppercase( 'bEEp' );\n* // returns 'BEEP'\n*/\nfunction uppercase( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a primitive string. Value: `'+str+'`.' );\n\t}\n\treturn str.toUpperCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = uppercase;\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 a string to uppercase.\n*\n* @module @stdlib/string-uppercase\n*\n* @example\n* var uppercase = require( '@stdlib/string-uppercase' );\n*\n* var str = uppercase( 'bEEp' );\n* // returns 'BEEP'\n*/\n\n// MODULES //\n\nvar uppercase = require( './uppercase.js' );\n\n\n// EXPORTS //\n\nmodule.exports = uppercase;\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\nvar lowercase = require( '@stdlib/string-lowercase' );\nvar uppercase = require( '@stdlib/string-uppercase' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is an uppercase string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an uppercase string\n*\n* @example\n* var bool = isUppercase( 'HELLO' );\n* // returns true\n*\n* @example\n* var bool = isUppercase( 'World' );\n* // returns false\n*\n* @example\n* var bool = isUppercase( '!' );\n* // returns false\n*\n* @example\n* var bool = isUppercase( 'salt and light' );\n* // returns false\n*/\nfunction isUppercase( value ) {\n\treturn (\n\t\tisString( value ) &&\n\t\tvalue === uppercase( value ) &&\n\t\tvalue !== lowercase( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUppercase;\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* Test if a value is an uppercase string.\n*\n* @module @stdlib/assert-is-uppercase\n*\n* @example\n* var isUppercase = require( '@stdlib/assert-is-uppercase' );\n*\n* var bool = isUppercase( 'HELLO' );\n* // returns true\n*\n* bool = isUppercase( 'World' );\n* // returns false\n*/\n\n// MODULES //\n\nvar isUppercase = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isUppercase;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is finite.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is finite\n*\n* @example\n* var bool = isfinite( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isfinite( -2.0e64 );\n* // returns true\n*\n* @example\n* var bool = isfinite( Infinity );\n* // returns false\n*\n* @example\n* var bool = isfinite( -Infinity );\n* // returns false\n*/\nfunction isfinite( x ) {\n\treturn (\n\t\t// NaN check (x !== x ):\n\t\tx === x &&\n\n\t\t// +-infinity check:\n\t\tx > NINF &&\n\t\tx < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isfinite;\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* Test if a double-precision floating-point numeric value is finite.\n*\n* @module @stdlib/math-base-assert-is-finite\n*\n* @example\n* var isfinite = require( '@stdlib/math-base-assert-is-finite' );\n*\n* var bool = isfinite( 5.0 );\n* // returns true\n*\n* bool = isfinite( -2.0e64 );\n* // returns true\n*\n* bool = isfinite( Infinity );\n* // returns false\n*\n* bool = isfinite( -Infinity );\n* // returns false\n*/\n\n// MODULES //\n\nvar isfinite = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isfinite;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue.valueOf() >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a nonnegative integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a nonnegative integer\n*\n* @example\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( null );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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* Test if a value is a nonnegative integer.\n*\n* @module @stdlib/assert-is-nonnegative-integer\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' );\n*\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* bool = isNonNegativeInteger( null );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isObject;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNonNegativeInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isNonNegativeInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar FLOAT64_MAX_SAFE_INTEGER = require( '@stdlib/constants-float64-max-safe-integer' );\n\n\n// MAIN //\n\n/**\n* Repeats a string a specified number of times and returns the concatenated result.\n*\n* ## Method\n*\n* The algorithmic trick used in the implementation is to treat string concatenation the same as binary addition (i.e., any natural number (nonnegative integer) can be expressed as a sum of powers of two).\n*\n* For example,\n*\n* ```text\n* n = 10 => 1010 => 2^3 + 2^0 + 2^1 + 2^0\n* ```\n*\n* We can produce a 10-repeat string by \"adding\" the results of a 8-repeat string and a 2-repeat string.\n*\n* The implementation is then as follows:\n*\n* 1. Let `s` be the string to be repeated and `o` be an output string.\n*\n* 2. Initialize an output string `o`.\n*\n* 3. Check the least significant bit to determine if the current `s` string should be \"added\" to the output \"total\".\n*\n* - if the bit is a one, add\n* - otherwise, move on\n*\n* 4. Double the string `s` by adding `s` to `s`.\n*\n* 5. Right-shift the bits of `n`.\n*\n* 6. Check if we have shifted off all bits.\n*\n* - if yes, done.\n* - otherwise, move on\n*\n* 7. Repeat 3-6.\n*\n* The result is that, as the string is repeated, we continually check to see if the doubled string is one which we want to add to our \"total\".\n*\n* The algorithm runs in `O(log_2(n))` compared to `O(n)`.\n*\n*\n* @param {string} str - string to repeat\n* @param {NonNegativeInteger} n - number of times to repeat the string\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument must be a nonnegative integer\n* @throws {RangeError} output string length must not exceed maximum allowed string length\n* @returns {string} repeated string\n*\n* @example\n* var str = repeat( 'a', 5 );\n* // returns 'aaaaa'\n*\n* @example\n* var str = repeat( '', 100 );\n* // returns ''\n*\n* @example\n* var str = repeat( 'beep', 0 );\n* // returns ''\n*/\nfunction repeat( str, n ) {\n\tvar rpt;\n\tvar cnt;\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string. Value: `' + str + '`.' );\n\t}\n\tif ( !isNonNegativeInteger( n ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a nonnegative integer. Value: `' + n + '`.' );\n\t}\n\tif ( str.length === 0 || n === 0 ) {\n\t\treturn '';\n\t}\n\t// Check that output string will not exceed the maximum string length:\n\tif ( str.length * n > FLOAT64_MAX_SAFE_INTEGER ) {\n\t\tthrow new RangeError( 'invalid argument. Output string length exceeds maximum allowed string length.' );\n\t}\n\trpt = '';\n\tcnt = n;\n\tfor ( ; ; ) {\n\t\t// If the count is odd, append the current concatenated string:\n\t\tif ( (cnt&1) === 1 ) {\n\t\t\trpt += str;\n\t\t}\n\t\t// Right-shift the bits:\n\t\tcnt >>>= 1;\n\t\tif ( cnt === 0 ) {\n\t\t\tbreak;\n\t\t}\n\t\t// Double the string:\n\t\tstr += str;\n\t}\n\treturn rpt;\n}\n\n\n// EXPORTS //\n\nmodule.exports = repeat;\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* Repeat a string a specified number of times and return the concatenated result.\n*\n* @module @stdlib/string-repeat\n*\n* @example\n* var replace = require( '@stdlib/string-repeat' );\n*\n* var str = repeat( 'a', 5 );\n* // returns 'aaaaa'\n*\n* str = repeat( '', 100 );\n* // returns ''\n*\n* str = repeat( 'beep', 0 );\n* // returns ''\n*/\n\n// MODULES //\n\nvar repeat = require( './repeat.js' );\n\n\n// EXPORTS //\n\nmodule.exports = repeat;\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* Maximum safe double-precision floating-point integer.\n*\n* @module @stdlib/constants-float64-max-safe-integer\n* @type {number}\n*\n* @example\n* var FLOAT64_MAX_SAFE_INTEGER = require( '@stdlib/constants-float64-max-safe-integer' );\n* // returns 9007199254740991\n*/\n\n\n// MAIN //\n\n/**\n* Maximum safe double-precision floating-point integer.\n*\n* ## Notes\n*\n* The integer has the value\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n* @see [Safe Integers]{@link http://www.2ality.com/2013/10/safe-integers.html}\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_MAX_SAFE_INTEGER = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_MAX_SAFE_INTEGER;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a string starts with the characters of another string.\n*\n* @param {string} str - input string\n* @param {string} search - search string\n* @param {integer} [position=0] - position at which to start searching\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument must be a string primitive\n* @throws {TypeError} third argument must be an integer\n* @returns {boolean} boolean indicating if the input string starts with the search string\n*\n* @example\n* var bool = startsWith( 'Remember the story I used to tell you when you were a boy?', 'Remember' );\n* // returns true\n*\n* @example\n* var bool = startsWith( 'Remember the story I used to tell you when you were a boy?', 'Remember, remember' );\n* // returns false\n*\n* @example\n* var bool = startsWith( 'To be, or not to be, that is the question.', 'To be' );\n* // returns true\n*\n* @example\n* var bool = startsWith( 'To be, or not to be, that is the question.', 'to be' );\n* // returns false\n*\n* @example\n* var bool = startsWith( 'To be, or not to be, that is the question.', 'to be', 14 );\n* // returns true\n*\n* @example\n* var bool = startsWith( 'To be, or not to be, that is the question.', 'quest', -9 );\n* // returns true\n*/\nfunction startsWith( str, search, position ) {\n\tvar pos;\n\tvar i;\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( !isString( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive. Value: `' + search + '`.' );\n\t}\n\tif ( arguments.length > 2 ) {\n\t\tif ( !isInteger( position ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Third argument must be an integer. Value: `' + position + '`.' );\n\t\t}\n\t\tif ( position < 0 ) {\n\t\t\tpos = str.length + position;\n\t\t} else {\n\t\t\tpos = position;\n\t\t}\n\t} else {\n\t\tpos = 0;\n\t}\n\tif ( search.length === 0 ) {\n\t\treturn true;\n\t}\n\tif (\n\t\tpos < 0 ||\n\t\tpos + search.length > str.length\n\t) {\n\t\treturn false;\n\t}\n\tfor ( i = 0; i < search.length; i++ ) {\n\t\tif ( str.charCodeAt( pos + i ) !== search.charCodeAt( i ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n\n// EXPORTS //\n\nmodule.exports = startsWith;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar repeat = require( '@stdlib/string-repeat' );\nvar startsWith = require( '@stdlib/string-starts-with' );\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWith( str, '-' ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + repeat( '0', pad ) :\n\t\trepeat( '0', pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = zeroPad;\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* Test if a string starts with the characters of another string.\n*\n* @module @stdlib/string-starts-with\n*\n* @example\n* var startsWith = require( '@stdlib/string-starts-with' );\n*\n* var str = 'Fair is foul, and foul is fair, hover through fog and filthy air';\n* var bool = startsWith( str, 'Fair' );\n* // returns true\n*\n* bool = startsWith( str, 'fair' );\n* // returns false\n*\n* bool = startsWith( str, 'foul', 8 );\n* // returns true\n*\n* bool = startsWith( str, 'filthy', -10 );\n* // returns true\n*/\n\n// MODULES //\n\nvar startsWith = require( './starts_with.js' );\n\n\n// EXPORTS //\n\nmodule.exports = startsWith;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isUppercase = require( '@stdlib/assert-is-uppercase' );\nvar uppercase = require( '@stdlib/string-uppercase' );\nvar lowercase = require( '@stdlib/string-lowercase' );\nvar isfinite = require( '@stdlib/math-base-assert-is-finite' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar zeroPad = require( './zero_pad.js' );\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isfinite( i ) ) {\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( isUppercase( token.specifier ) ) ?\n\t\t\tuppercase( out ) :\n\t\t\tlowercase( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = formatInteger;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// VARIABLES //\n\nvar RE_CHARS = /[-\\/\\\\^$*+?.()|[\\]{}]/g; // eslint-disable-line no-useless-escape\n\n\n// MAIN //\n\n/**\n* Escapes a regular expression string.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} first argument must be a string primitive\n* @returns {string} escaped string\n*\n* @example\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\nfunction rescape( str ) {\n\tvar len;\n\tvar s;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Check if the string starts with a forward slash...\n\tif ( str[ 0 ] === '/' ) {\n\t\t// Find the last forward slash...\n\t\tlen = str.length;\n\t\tfor ( i = len-1; i >= 0; i-- ) {\n\t\t\tif ( str[ i ] === '/' ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:\n\tif ( i === void 0 || i <= 0 ) {\n\t\treturn str.replace( RE_CHARS, '\\\\$&' );\n\t}\n\t// We need to de-construct the string...\n\ts = str.substring( 1, i );\n\n\t// Only escape the characters between the `/`:\n\ts = s.replace( RE_CHARS, '\\\\$&' );\n\n\t// Reassemble:\n\tstr = str[ 0 ] + s + str.substring( i );\n\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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* Escape a regular expression string or pattern.\n*\n* @module @stdlib/utils-escape-regexp-string\n*\n* @example\n* var rescape = require( '@stdlib/utils-escape-regexp-string' );\n*\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\n\n// MODULES //\n\nvar rescape = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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\nvar RE = /./;\n\n\n// EXPORTS //\n\nmodule.exports = RE;\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* Tests if a value is a boolean primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean primitive\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns false\n*/\nfunction isBoolean( value ) {\n\treturn ( typeof value === 'boolean' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Boolean.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean object\n*\n* @example\n* var bool = isBoolean( true );\n* // returns false\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Boolean ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Boolean]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a boolean\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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* Test if a value is a boolean.\n*\n* @module @stdlib/assert-is-boolean\n*\n* @example\n* var isBoolean = require( '@stdlib/assert-is-boolean' );\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* // Use interface to check for boolean primitives...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( true ) );\n* // returns false\n*\n* @example\n* // Use interface to check for boolean objects...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isObject;\n*\n* var bool = isBoolean( true );\n* // returns false\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isBoolean = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isBoolean, 'isPrimitive', isPrimitive );\nsetReadOnly( isBoolean, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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// MAIN //\n\n/**\n* Returns the global object using code generation.\n*\n* @private\n* @returns {Object} global object\n*/\nfunction getGlobal() {\n\treturn new Function( 'return this;' )(); // eslint-disable-line no-new-func\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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// MAIN //\n\nvar obj = ( typeof self === 'object' ) ? self : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof window === 'object' ) ? window : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof global === 'object' ) ? global : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar getThis = require( './codegen.js' );\nvar Self = require( './self.js' );\nvar Win = require( './window.js' );\nvar Global = require( './global.js' );\n\n\n// MAIN //\n\n/**\n* Returns the global object.\n*\n* ## Notes\n*\n* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.\n*\n* @param {boolean} [codegen=false] - boolean indicating whether to use code generation to resolve the global object\n* @throws {TypeError} must provide a boolean\n* @throws {Error} unable to resolve global object\n* @returns {Object} global object\n*\n* @example\n* var g = getGlobal();\n* // returns {...}\n*/\nfunction getGlobal( codegen ) {\n\tif ( arguments.length ) {\n\t\tif ( !isBoolean( codegen ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Must provide a boolean primitive. Value: `'+codegen+'`.' );\n\t\t}\n\t\tif ( codegen ) {\n\t\t\treturn getThis();\n\t\t}\n\t\t// Fall through...\n\t}\n\t// Case: browsers and web workers\n\tif ( Self ) {\n\t\treturn Self;\n\t}\n\t// Case: browsers\n\tif ( Win ) {\n\t\treturn Win;\n\t}\n\t// Case: Node.js\n\tif ( Global ) {\n\t\treturn Global;\n\t}\n\t// Case: unknown\n\tthrow new Error( 'unexpected error. Unable to resolve global object.' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar getGlobal = require( '@stdlib/utils-global' );\n\n\n// MAIN //\n\nvar root = getGlobal();\nvar nodeList = root.document && root.document.childNodes;\n\n\n// EXPORTS //\n\nmodule.exports = nodeList;\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* Return the global object.\n*\n* @module @stdlib/utils-global\n*\n* @example\n* var getGlobal = require( '@stdlib/utils-global' );\n*\n* var g = getGlobal();\n* // returns {...}\n*/\n\n// MODULES //\n\nvar getGlobal = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar typedarray = Int8Array; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = typedarray;\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\nvar RE = require( './fixtures/re.js' );\nvar nodeList = require( './fixtures/nodelist.js' );\nvar typedarray = require( './fixtures/typedarray.js' );\n\n\n// MAIN //\n\n/**\n* Checks whether a polyfill is needed when using the `typeof` operator.\n*\n* @private\n* @returns {boolean} boolean indicating whether a polyfill is needed\n*/\nfunction check() {\n\tif (\n\t\t// Chrome 1-12 returns 'function' for regular expression instances (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof):\n\t\ttypeof RE === 'function' ||\n\n\t\t// Safari 8 returns 'object' for typed array and weak map constructors (underscore #1929):\n\t\ttypeof typedarray === 'object' ||\n\n\t\t// PhantomJS 1.9 returns 'function' for `NodeList` instances (underscore #2236):\n\t\ttypeof nodeList === 'function'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\nfunction reFunctionName() {\n\treturn /^\\s*function\\s*([^(]*)/i;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @module @stdlib/regexp-function-name\n*\n* @example\n* var reFunctionName = require( '@stdlib/regexp-function-name' );\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reFunctionName = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reFunctionName, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\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\nvar reFunctionName = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Captures everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* Regular expression: `/^\\s*function\\s*([^(]*)/i`\n*\n* - `/^\\s*`\n* - Match zero or more spaces at beginning\n*\n* - `function`\n* - Match the word `function`\n*\n* - `\\s*`\n* - Match zero or more spaces after the word `function`\n*\n* - `()`\n* - Capture\n*\n* - `[^(]*`\n* - Match anything except a left parenthesis `(` zero or more times\n*\n* - `/i`\n* - ignore case\n*\n* @constant\n* @type {RegExp}\n* @default /^\\s*function\\s*([^(]*)/i\n*/\nvar RE_FUNCTION_NAME = reFunctionName();\n\n\n// EXPORTS //\n\nmodule.exports = RE_FUNCTION_NAME;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar f;\n\n\n// FUNCTIONS //\n\n/**\n* Tests if a value is an array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an array\n*\n* @example\n* var bool = isArray( [] );\n* // returns true\n*\n* @example\n* var bool = isArray( {} );\n* // returns false\n*/\nfunction isArray( value ) {\n\treturn ( nativeClass( value ) === '[object Array]' );\n}\n\n\n// MAIN //\n\nif ( Array.isArray ) {\n\tf = Array.isArray;\n} else {\n\tf = isArray;\n}\n\n\n// EXPORTS //\n\nmodule.exports = f;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Returns a function which tests if every element in an array passes a test condition.\n*\n* @param {Function} predicate - function to apply\n* @throws {TypeError} must provide a function\n* @returns {Function} an array function\n*\n* @example\n* var isOdd = require( '@stdlib/assert-is-odd' );\n*\n* var arr1 = [ 1, 3, 5, 7 ];\n* var arr2 = [ 3, 5, 8 ];\n*\n* var validate = arrayfcn( isOdd );\n*\n* var bool = validate( arr1 );\n* // returns true\n*\n* bool = validate( arr2 );\n* // returns false\n*/\nfunction arrayfcn( predicate ) {\n\tif ( typeof predicate !== 'function' ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a function. Value: `' + predicate + '`.' );\n\t}\n\treturn every;\n\n\t/**\n\t* Tests if every element in an array passes a test condition.\n\t*\n\t* @private\n\t* @param {*} value - value to test\n\t* @returns {boolean} boolean indicating whether a value is an array for which all elements pass a test condition\n\t*/\n\tfunction every( value ) {\n\t\tvar len;\n\t\tvar i;\n\t\tif ( !isArray( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tlen = value.length;\n\t\tif ( len === 0 ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( predicate( value[ i ] ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayfcn;\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* Tests if a value is object-like.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is object-like\n*\n* @example\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( [] );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( null );\n* // returns false\n*/\nfunction isObjectLike( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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* Test if a value is object-like.\n*\n* @module @stdlib/assert-is-object-like\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' );\n*\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* bool = isObjectLike( [] );\n* // returns true\n*\n* bool = isObjectLike( null );\n* // returns false\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' ).isObjectLikeArray;\n*\n* var bool = isObjectLike( [ {}, [] ] );\n* // returns true\n*\n* bool = isObjectLike( [ {}, '3.0' ] );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar arrayfun = require( '@stdlib/assert-tools-array-function' );\nvar isObjectLike = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( isObjectLike, 'isObjectLikeArray', arrayfun( isObjectLike ) );\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Buffer instance.\n*\n* @param {*} value - value to validate\n* @returns {boolean} boolean indicating if a value is a Buffer instance\n*\n* @example\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( new Buffer( [1,2,3,4] ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( {} );\n* // returns false\n*\n* @example\n* var v = isBuffer( [] );\n* // returns false\n*/\nfunction isBuffer( value ) {\n\treturn (\n\t\tisObjectLike( value ) &&\n\t\t(\n\t\t\t// eslint-disable-next-line no-underscore-dangle\n\t\t\tvalue._isBuffer || // for envs missing Object.prototype.constructor (e.g., Safari 5-7)\n\t\t\t(\n\t\t\t\tvalue.constructor &&\n\n\t\t\t\t// WARNING: `typeof` is not a foolproof check, as certain envs consider RegExp and NodeList instances to be functions\n\t\t\t\ttypeof value.constructor.isBuffer === 'function' &&\n\t\t\t\tvalue.constructor.isBuffer( value )\n\t\t\t)\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar RE = require( '@stdlib/regexp-function-name' ).REGEXP;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\n\n\n// MAIN //\n\n/**\n* Determines the name of a value's constructor.\n*\n* @param {*} v - input value\n* @returns {string} name of a value's constructor\n*\n* @example\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* @example\n* var v = constructorName( 5 );\n* // returns 'Number'\n*\n* @example\n* var v = constructorName( null );\n* // returns 'Null'\n*\n* @example\n* var v = constructorName( undefined );\n* // returns 'Undefined'\n*\n* @example\n* var v = constructorName( function noop() {} );\n* // returns 'Function'\n*/\nfunction constructorName( v ) {\n\tvar match;\n\tvar name;\n\tvar ctor;\n\tname = nativeClass( v ).slice( 8, -1 );\n\tif ( (name === 'Object' || name === 'Error') && v.constructor ) {\n\t\tctor = v.constructor;\n\t\tif ( typeof ctor.name === 'string' ) {\n\t\t\treturn ctor.name;\n\t\t}\n\t\tmatch = RE.exec( ctor.toString() );\n\t\tif ( match ) {\n\t\t\treturn match[ 1 ];\n\t\t}\n\t}\n\tif ( isBuffer( v ) ) {\n\t\treturn 'Buffer';\n\t}\n\treturn name;\n}\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// NOTES //\n\n/*\n* Built-in `typeof` operator behavior:\n*\n* ```text\n* typeof null => 'object'\n* typeof undefined => 'undefined'\n* typeof 'a' => 'string'\n* typeof 5 => 'number'\n* typeof NaN => 'number'\n* typeof true => 'boolean'\n* typeof false => 'boolean'\n* typeof {} => 'object'\n* typeof [] => 'object'\n* typeof function foo(){} => 'function'\n* typeof function* foo(){} => 'object'\n* typeof Symbol() => 'symbol'\n* ```\n*\n*/\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\tvar type;\n\n\t// Address `typeof null` => `object` (see http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null):\n\tif ( v === null ) {\n\t\treturn 'null';\n\t}\n\ttype = typeof v;\n\n\t// If the `typeof` operator returned something other than `object`, we are done. Otherwise, we need to check for an internal class name or search for a constructor.\n\tif ( type === 'object' ) {\n\t\treturn ctorName( v ).toLowerCase();\n\t}\n\treturn type;\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine the name of a value's constructor.\n*\n* @module @stdlib/utils-constructor-name\n*\n* @example\n* var constructorName = require( '@stdlib/utils-constructor-name' );\n*\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* v = constructorName( {} );\n* // returns 'Object'\n*\n* v = constructorName( true );\n* // returns 'Boolean'\n*/\n\n// MODULES //\n\nvar constructorName = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\treturn ctorName( v ).toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine a value's type.\n*\n* @module @stdlib/utils-type-of\n*\n* @example\n* var typeOf = require( '@stdlib/utils-type-of' );\n*\n* var str = typeOf( 'a' );\n* // returns 'string'\n*\n* str = typeOf( 5 );\n* // returns 'number'\n*/\n\n// MODULES //\n\nvar usePolyfill = require( './check.js' );\nvar typeOf = require( './typeof.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main = ( usePolyfill() ) ? polyfill : typeOf;\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar typeOf = require( '@stdlib/utils-type-of' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a function.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a function\n*\n* @example\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\nfunction isFunction( value ) {\n\t// Note: cannot use `typeof` directly, as various browser engines incorrectly return `'function'` when operating on non-function objects, such as regular expressions and NodeLists.\n\treturn ( typeOf( value ) === 'function' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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* Test if a value is a function.\n*\n* @module @stdlib/assert-is-function\n*\n* @example\n* var isFunction = require( '@stdlib/assert-is-function' );\n*\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\n\n// MODULES //\n\nvar isFunction = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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\nvar exec = require( './exec.js' );\n\n\n// MAIN //\n\n/**\n* Attempts to call a `RegExp` method.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if able to call a `RegExp` method\n*/\nfunction test( value ) {\n\ttry {\n\t\texec.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar exec = RegExp.prototype.exec; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = exec;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2exec.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a regular expression.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a regular expression\n*\n* @example\n* var bool = isRegExp( /\\.+/ );\n* // returns true\n*\n* @example\n* var bool = isRegExp( {} );\n* // returns false\n*/\nfunction isRegExp( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof RegExp ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object RegExp]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isRegExp;\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\nvar rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument argument must be a string primitive or regular expression\n* @throws {TypeError} third argument must be a string primitive or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive or regular expression. Value: `' + search + '`.' );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( 'invalid argument. Third argument must be a string primitive or replacement function. Value: `' + newval + '`.' );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Computes the absolute value of a double-precision floating-point number `x`.\n*\n* @param {number} x - input value\n* @returns {number} absolute value\n*\n* @example\n* var v = abs( -1.0 );\n* // returns 1.0\n*\n* @example\n* var v = abs( 2.0 );\n* // returns 2.0\n*\n* @example\n* var v = abs( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = abs( -0.0 );\n* // returns 0.0\n*\n* @example\n* var v = abs( NaN );\n* // returns NaN\n*/\nfunction abs( x ) {\n\treturn Math.abs( x ); // eslint-disable-line stdlib/no-builtin-math\n}\n\n\n// EXPORTS //\n\nmodule.exports = abs;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isUppercase = require( '@stdlib/assert-is-uppercase' );\nvar uppercase = require( '@stdlib/string-uppercase' );\nvar lowercase = require( '@stdlib/string-lowercase' );\nvar replace = require( '@stdlib/string-replace' );\nvar isfinite = require( '@stdlib/math-base-assert-is-finite' );\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar abs = require( '@stdlib/math-base-special-abs' );\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isfinite( f ) ) {\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( isUppercase( token.specifier ) ) ?\n\t\tuppercase( out ) :\n\t\tlowercase( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// MAIN //\n\n/**\n* Tokenizes a string.\n*\n* @private\n* @param {string} str - input string\n* @returns {Array} tokens\n*/\nfunction tokenize( str ) {\n\tvar lastIndex;\n\tvar content;\n\tvar tokens;\n\tvar parsed;\n\tvar match;\n\n\tlastIndex = 0;\n\ttokens = [];\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( lastIndex, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\tparsed = parse( match, tokens.length );\n\t\tif ( parsed ) {\n\t\t\ttokens.push( parsed );\n\t\t}\n\t\tlastIndex = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( lastIndex );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n\n\t/**\n\t* Parses a delimeter.\n\t*\n\t* @private\n\t* @param {Array} match - regular expression match\n\t* @returns {Object} delimeter token object\n\t*/\n\tfunction parse( match ) {\n\t\treturn {\n\t\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t\t'flags': match[ 2 ],\n\t\t\t'width': match[ 3 ],\n\t\t\t'hasPeriod': match[ 4 ] === '.',\n\t\t\t'precision': match[ 5 ],\n\t\t\t'specifier': match[ 6 ]\n\t\t};\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = tokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar repeat = require( '@stdlib/string-repeat' );\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + repeat( ' ', pad ) :\n\t\trepeat( ' ', pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar contains = require( '@stdlib/assert-contains' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar formatInteger = require( './format_integer.js' );\nvar formatDouble = require( './format_double.js' );\nvar tokenize = require( './tokenize.js' );\nvar spacePad = require( './space_pad.js' );\nvar zeroPad = require( './zero_pad.js' );\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} must provide a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a string. Value: `' + str + '`.' );\n\t}\n\ttokens = tokenize( str );\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t}\n\t\telse {\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = !contains( flags, '-' );\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.precision === '*' && token.hasPeriod ) {\n\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\ttoken.hasPeriod = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( token.hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( token.hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !token.hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = format;\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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: %u. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Insert supplied variable values into a format string.\n*\n* @module @stdlib/string-format\n*\n* @example\n* var format = require( '@stdlib/string-format' );\n*\n* var out = format( '%s %s!', 'Hello', 'World' );\n* // returns 'Hello World!'\n*\n* out = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\n\n// MODULES //\n\nvar format = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = format;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\n\n// MODULES //\n\nvar sub2ind = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = sub2ind;\n"],"names":["defineProperty","Object","has_define_property_support","err","builtin","objectProtoype","prototype","toStr","toString","defineGetter","__defineGetter__","defineSetter","__defineSetter__","lookupGetter","__lookupGetter__","lookupSetter","__lookupSetter__","polyfill","obj","prop","descriptor","hasValue","hasGet","hasSet","call","TypeError","__proto__","value","Error","get","set","require$$1","require$$2","require$$0","main","configurable","enumerable","writable","lib","primitive","FLG","Symbol","hasSymbols","toStringTag","tostring","native_class","v","has","hasOwnProperty","property","toStrTag","hasOwnProp","isOwn","tag","out","valueOf","String","nativeClass","test","object","isPrimitive","isObject","setReadOnly","isString","require$$3","floor","Math","x","isInteger","length","Number","isNumber","POSITIVE_INFINITY","NEGATIVE_INFINITY","PINF","NINF","isInt","integer","isNan","isnan","isCollection","contains_1","val","searchValue","position","len","pos","i","arguments","indexOf","str","toLowerCase","toUpperCase","lowercase","uppercase","isNonNegativeInteger","n","rpt","cnt","RangeError","starts_with","search","charCodeAt","repeat","startsWith","zero_pad","width","right","negative","pad","substr","isUppercase","isfinite","require$$4","zeroPad","require$$5","format_integer","token","base","specifier","arg","parseInt","precision","padRight","sign","alternate","charAt","RE_CHARS","s","replace","substring","re","Boolean","isBoolean","codegen","Function","self_1","self","window_1","window","global","module","exports","getThis","Self","Win","Global","root","nodeList","document","childNodes","typedarray","Int8Array","RE","check_1","reFunctionName","isArray","Array","isObjectLike","predicate","arrayfun","REGEXP","isBuffer","_isBuffer","constructor","match","name","ctor","slice","exec","ctorName","typeOf","type","RegExp","rescape","isFunction","isRegExp","newval","abs","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","format_double","digits","f","parseFloat","toExponential","toFixed","toPrecision","contains","formatInteger","formatDouble","tokenize","lastIndex","content","tokens","parsed","push","parse","mapping","flags","hasPeriod","spacePad","require$$7","fromCharCode","flag","num","j","padZeros","maxWidth","format","strides","offset","nmodes","shape","ndims","modes","mode","idx","m"],"mappings":";ifAsBA,ICAIA,EDA0C,mBAA1BC,OAAOD,eAAkCC,OAAOD,eAAiB,KC4BrF,IAAAE,EAbA,WAEC,IAEC,OADAF,EAAgB,GAAI,IAAK,KAClB,EACN,MAAQG,GACT,OAAO,ICiBTC,EALqBH,OAAOD,eC/BxBK,EAAiBJ,OAAOK,UACxBC,EAAQF,EAAeG,SACvBC,EAAeJ,EAAeK,iBAC9BC,EAAeN,EAAeO,iBAC9BC,EAAeR,EAAeS,iBAC9BC,EAAeV,EAAeW,iBAuFlC,IAAAC,EAnDA,SAAyBC,EAAKC,EAAMC,GACnC,IAAId,EACAe,EACAC,EACAC,EAEJ,GAAoB,iBAARL,GAA4B,OAARA,GAAsC,mBAAtBX,EAAMiB,KAAMN,GAC3D,MAAM,IAAIO,UAAW,+DAAiEP,EAAM,MAE7F,GAA2B,iBAAfE,GAA0C,OAAfA,GAAoD,mBAA7Bb,EAAMiB,KAAMJ,GACzE,MAAM,IAAIK,UAAW,oEAAsEL,EAAa,MAyBzG,IAvBAC,EAAa,UAAWD,KAGtBP,EAAaW,KAAMN,EAAKC,IACxBJ,EAAaS,KAAMN,EAAKC,IAGxBb,EAAYY,EAAIQ,UAChBR,EAAIQ,UAAYrB,SAGTa,EAAKC,GACZD,EAAKC,GAASC,EAAWO,MAGzBT,EAAIQ,UAAYpB,GAEhBY,EAAKC,GAASC,EAAWO,OAG3BL,EAAW,QAASF,EACpBG,EAAW,QAASH,EAEfC,IAAcC,GAAUC,GAC5B,MAAM,IAAIK,MAAO,wHASlB,OANKN,GAAUb,GACdA,EAAae,KAAMN,EAAKC,EAAMC,EAAWS,KAErCN,GAAUZ,GACdA,EAAaa,KAAMN,EAAKC,EAAMC,EAAWU,KAEnCZ,GCrEJd,EAAU2B,EACVd,EAAWe,ECpBXhC,EDkB2BiC,IASb7B,EAEAa,ECMlB,IAAAiB,EAZA,SAAmChB,EAAKC,EAAMQ,GAC7C3B,EAAgBkB,EAAKC,EAAM,CAC1BgB,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZV,MAASA,KCJXW,EAL+BL,ECA/B,IAAAM,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCMjB,ICdIa,EDIJ,WACC,MACmB,mBAAXC,QACoB,iBAApBA,OAAQ,OCPPC,GAqBV,ICTAJ,EDEA,WACC,OAASE,GAAqC,iBAAvBC,OAAOE,aEf/BC,EALY3C,OAAOK,UAAUE,SCAzBD,EAAQ0B,EAiCZ,IAAAY,EAPA,SAAsBC,GACrB,OAAOvC,EAAMiB,KAAMsB,IC3BhBC,EAAM9C,OAAOK,UAAU0C,eAyC3B,ICjBAV,EDIA,SAAqBX,EAAOsB,GAC3B,OACCtB,MAAAA,GAKMoB,EAAIvB,KAAMG,EAAOsB,IEnCrBC,EAA+B,mBAAXT,OAA0BA,OAAOE,YAAc,GCAnEQ,EAAalB,EACbU,EDIaO,ECHb3C,EAAQyB,EAwDZ,ICpCI5B,EAAU2B,EACVd,EDKJ,SAAsB6B,GACrB,IAAIM,EACAC,EACAC,EAEJ,GAAKR,MAAAA,EACJ,OAAOvC,EAAMiB,KAAMsB,GAEpBO,EAAMP,EAAGH,GACTS,EAAQD,EAAYL,EAAGH,GAGvB,IACCG,EAAGH,QAAgB,EAClB,MAAQxC,GACT,OAAOI,EAAMiB,KAAMsB,GASpB,OAPAQ,EAAM/C,EAAMiB,KAAMsB,GAEbM,EACJN,EAAGH,GAAgBU,SAEZP,EAAGH,GAEJW,GCdRhB,EAjBqBL,IASNhB,EAEAb,EChCXmD,ECDUC,OAAOlD,UAAUiD,QDyB/B,IEvBIE,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADA4B,EAAQ/B,KAAMG,IACP,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBP,IA0CrB,IAAA0B,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB6B,SAGjBhB,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MClCpBiC,EAAc3B,EACd4B,EAAW9B,EA0Bf,ICSI+B,EAAc7B,EACd8B,EDjBJ,SAAmBpC,GAClB,OAASiC,EAAajC,IAAWkC,EAAUlC,ICkBxCkC,EAAWG,EAKfF,EAAaC,EAAU,cANL/B,GAOlB8B,EAAaC,EAAU,WAAYF,GAKnC,IAAAvB,EAAiByB,EClDbE,ECsBQC,KAAKD,MDIjB,IENA3B,EFDA,SAAoB6B,GACnB,OAAQF,EAAME,KAAOA,GGpBlBC,EAAYnC,EAkChB,ICdAK,EDAA,SAAuBX,GACtB,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAM0C,QACbD,EAAWzC,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QENqB,kBCE7B,IAAA9B,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCAjBW,ECjBiBgC,OCAb9D,ECASyB,EAMS3B,UAAUE,SDkBhC,IEvBIiD,EAAc1B,EACduC,EAAStC,EACT0B,EFSJ,SAAe/B,GACd,IAEC,OADAnB,EAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IETLqC,EARiBP,IA2CrB,IAAA0B,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB2C,IAGjB9B,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MCnCpBiC,GAAc3B,EACd4B,GAAW9B,EAkCf,ICOI+B,GAAc7B,EACdsC,GDfJ,SAAmB5C,GAClB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,EAKfF,GAAaS,GAAU,cANLvC,GAOlB8B,GAAaS,GAAU,WAAYV,IAKnC,IAAAvB,GAAiBiC,GCvBjBjC,GALmBgC,OAAOE,kBCS1BlC,GA1BaL,EAqBawC,kBChCtBC,GAAOzC,GACP0C,GAAO5C,GACP6C,GAAQ5C,EAuBZ,IAAA6C,GAXA,SAAoBlD,GACnB,OACCA,EAAQ+C,IACR/C,EAAQgD,IACRC,GAAOjD,IClBL4C,GAAWtC,GAAsC2B,YACjDgB,GAAQ7C,GA6BZ,IAAAQ,GAVA,SAAoBZ,GACnB,OACC4C,GAAU5C,IACViD,GAAOjD,ICvBL4C,GAAWtC,GAAsC4B,SACjDe,GAAQ7C,GA6BZ,IAAA4B,GAVA,SAAoBhC,GACnB,OACC4C,GAAU5C,IACViD,GAAOjD,EAAM4B,YCvBXK,GAAc3B,GACd4B,GAAW9B,GAkCf,ICMI+B,GAAc7B,EACdmC,GDdJ,SAAoBzC,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICexCkC,GAAWG,GAKfF,GAAaM,GAAW,cANNpC,IAOlB8B,GAAaM,GAAW,WAAYP,IAKpC,IAAAvB,GAAiB8B,GClCjB,ICDA9B,GDNA,SAAgB6B,GACf,OAASA,GAAMA,GEfZI,GAAWtC,GAAsC2B,YACjDkB,GAAQ/C,GAiCZ,IAAAQ,GAVA,SAAgBZ,GACf,OACC4C,GAAU5C,IACVmD,GAAOnD,IC3BL4C,GAAWtC,GAAsC4B,SACjDiB,GAAQ/C,GA6BZ,IAAA4B,GAVA,SAAgBhC,GACf,OACC4C,GAAU5C,IACVmD,GAAOnD,EAAM4B,YCvBXK,GAAc3B,GACd4B,GAAW9B,GAkCf,ICOI+B,GAAc7B,EACd8C,GDfJ,SAAgBpD,GACf,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAaiB,GAAO,cANF/C,IAOlB8B,GAAaiB,GAAO,WAAYlB,IAKhC,ICxDImB,GAAe/C,EACfmC,GAAYrC,GAAuC6B,YACnDG,GAAW/B,EAAsC4B,YACjDmB,GDqDaA,GCrD8BnB,YA4F/C,IAAAqB,GA/CA,SAAmBC,EAAKC,EAAaC,GACpC,IAAIC,EACAC,EACAC,EACJ,IAAMP,GAAcE,KAAUnB,GAAUmB,GACvC,MAAM,IAAIzD,UAAW,gEAAkEyD,EAAM,MAE9F,GAAKM,UAAUnB,OAAS,EACvB,MAAM,IAAIzC,MAAO,8DAElB,GAAK4D,UAAUnB,OAAS,EAAI,CAC3B,IAAMD,GAAWgB,GAChB,MAAM,IAAI3D,UAAW,gEAAkE2D,EAAW,OAEnGE,EAAMF,GACK,IACVE,EAAM,QAGPA,EAAM,EAEP,GAAKvB,GAAUmB,GAAQ,CACtB,IAAMnB,GAAUoB,GACf,MAAM,IAAI1D,UAAW,yEAA2E0D,EAAc,MAE/G,OAA4C,IAArCD,EAAIO,QAASN,EAAaG,GAGlC,GADAD,EAAMH,EAAIb,OACLU,GAAOI,GAAgB,CAC3B,IAAMI,EAAID,EAAKC,EAAIF,EAAKE,IACvB,GAAKR,GAAOG,EAAKK,IAChB,OAAO,EAGT,OAAO,EAER,IAAMA,EAAID,EAAKC,EAAIF,EAAKE,IACvB,GAAKL,EAAKK,KAAQJ,EACjB,OAAO,EAGT,OAAO,GC/DR7C,GALeL,GCrBX8B,GAAW9B,EAAsC2B,YA0BrD,ICTAtB,GDDA,SAAoBoD,GACnB,IAAM3B,GAAU2B,GACf,MAAM,IAAIjE,UAAW,8DAA8DiE,EAAI,MAExF,OAAOA,EAAIC,eEpBR5B,GAAW9B,EAAsC2B,YA0BrD,ICTAtB,GDDA,SAAoBoD,GACnB,IAAM3B,GAAU2B,GACf,MAAM,IAAIjE,UAAW,8DAA8DiE,EAAI,MAExF,OAAOA,EAAIE,eEpBRC,GAAY5D,GACZ6D,GAAY/D,GACZgC,GAAW/B,EAAsC4B,YAsCrD,ICpBAtB,GDSA,SAAsBX,GACrB,OACCoC,GAAUpC,IACVA,IAAUmE,GAAWnE,IACrBA,IAAUkE,GAAWlE,IEjCnB+C,GAAOzC,GACP0C,GAAO5C,GAyCX,IChBAO,GDEA,SAAmB6B,GAClB,OAECA,GAAMA,GAGNA,EAAIQ,IACJR,EAAIO,IEnCFN,GAAYnC,GAAuC2B,YA6BvD,IAAArB,GAVA,SAA+BZ,GAC9B,OACCyC,GAAWzC,IACXA,GAAS,GCtBPyC,GAAYnC,GAAuC4B,SA6BvD,IAAAF,GAVA,SAA+BhC,GAC9B,OACCyC,GAAWzC,IACXA,EAAM4B,WAAa,GCtBjBK,GAAc3B,GACd4B,GAAW9B,GAsCf,ICGI+B,GAAc7B,EACd8D,GDXJ,SAA+BpE,GAC9B,OAASiC,GAAajC,IAAWkC,GAAUlC,ICYxCkC,GAAWG,GAKfF,GAAaiC,GAAsB,cANjB/D,IAOlB8B,GAAaiC,GAAsB,WAAYlC,IAK/C,ICxDIkC,GDwDaA,GCxD6DnC,YAC1EG,GAAWhC,EAAsC6B,YAwGrD,IClFAtB,GD6CA,SAAiBoD,EAAKM,GACrB,IAAIC,EACAC,EACJ,IAAMnC,GAAU2B,GACf,MAAM,IAAIjE,UAAW,8DAAgEiE,EAAM,MAE5F,IAAMK,GAAsBC,GAC3B,MAAM,IAAIvE,UAAW,4EAA8EuE,EAAI,MAExG,GAAoB,IAAfN,EAAIrB,QAAsB,IAAN2B,EACxB,MAAO,GAGR,GAAKN,EAAIrB,OAAS2B,EEpDY,iBFqD7B,MAAM,IAAIG,WAAY,iFAIvB,IAFAF,EAAM,GACNC,EAAMF,EAGY,IAAP,EAAJE,KACLD,GAAOP,GAIK,KADbQ,KAAS,IAKTR,GAAOA,EAER,OAAOO,GGnGJ7B,GAAYnC,GAAuC2B,YACnDG,GAAWhC,EAAsC6B,YAiFrD,IAAAwC,GAzCA,SAAqBV,EAAKW,EAAQjB,GACjC,IAAIE,EACAC,EACJ,IAAMxB,GAAU2B,GACf,MAAM,IAAIjE,UAAW,wEAA0EiE,EAAM,MAEtG,IAAM3B,GAAUsC,GACf,MAAM,IAAI5E,UAAW,yEAA2E4E,EAAS,MAE1G,GAAKb,UAAUnB,OAAS,EAAI,CAC3B,IAAMD,GAAWgB,GAChB,MAAM,IAAI3D,UAAW,gEAAkE2D,EAAW,MAGlGE,EADIF,EAAW,EACTM,EAAIrB,OAASe,EAEbA,OAGPE,EAAM,EAEP,GAAuB,IAAlBe,EAAOhC,OACX,OAAO,EAER,GACCiB,EAAM,GACNA,EAAMe,EAAOhC,OAASqB,EAAIrB,OAE1B,OAAO,EAER,IAAMkB,EAAI,EAAGA,EAAIc,EAAOhC,OAAQkB,IAC/B,GAAKG,EAAIY,WAAYhB,EAAMC,KAAQc,EAAOC,WAAYf,GACrD,OAAO,EAGT,OAAO,GC5EJgB,GAAStE,GACTuE,GCqBavE,GDejB,IAAAwE,GAtBA,SAAkBf,EAAKgB,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQhB,EAAIrB,OACtB,OAAKwC,EAAM,IAGNL,GAAYd,EAAK,OACrBkB,GAAW,EACXlB,EAAMA,EAAIoB,OAAQ,IAEnBpB,EAAM,EACLA,EAAMa,GAAQ,IAAKM,GACnBN,GAAQ,IAAKM,GAAQnB,EACjBkB,IACJlB,EAAM,IAAMA,IAVLA,GEnBLqB,GAAc9E,GACd6D,GAAY/D,GACZ8D,GAAY7D,GACZgF,GAAWhD,GACXO,GAAW0C,GAAsCrD,YACjDsD,GAAUC,GAuFd,IAAAC,GA1EA,SAAwBC,GACvB,IAAIC,EACAhE,EACAiC,EAEJ,OAAS8B,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAhE,EAAM+D,EAAMG,IACZjC,EAAIkC,SAAUnE,EAAK,KACb0D,GAAUzB,GAAM,CACrB,IAAMhB,GAAUjB,GACf,MAAM,IAAI1B,MAAO,2BAA6B0B,GAE/CiC,EAAI,EAmCL,OAjCKA,EAAI,IAA2B,MAApB8B,EAAME,WAA8B,KAATD,KAC1C/B,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRjC,IAASiC,GAAI/E,SAAU8G,GAClBD,EAAMK,YACVpE,EAAM4D,GAAS5D,EAAK+D,EAAMK,UAAWL,EAAMM,WAE5CrE,EAAM,IAAMA,IAEZA,EAAMiC,EAAE/E,SAAU8G,GACZ/B,GAAM8B,EAAMK,UAENL,EAAMK,YACjBpE,EAAM4D,GAAS5D,EAAK+D,EAAMK,UAAWL,EAAMM,WAF3CrE,EAAM,GAIF+D,EAAMO,OACVtE,EAAM+D,EAAMO,KAAOtE,IAGP,KAATgE,IACCD,EAAMQ,YACVvE,EAAM,KAAOA,GAEdA,EAAQyD,GAAaM,EAAME,WAC1BzB,GAAWxC,GACXuC,GAAWvC,IAEC,IAATgE,GACCD,EAAMQ,WAAiC,MAApBvE,EAAIwE,OAAQ,KACnCxE,EAAM,IAAMA,GAGPA,GCtFJS,GAAW9B,EAAsC2B,YAKjDmE,GAAW,yBAqDf,ICzCAzF,GDIA,SAAkBoD,GACjB,IACIsC,EACAzC,EAEJ,IAAMxB,GAAU2B,GACf,MAAM,IAAIjE,UAAW,uEAAyEiE,EAAM,MAGrG,GAAkB,MAAbA,EAAK,GAGT,IAAMH,EADAG,EAAIrB,OACI,EAAGkB,GAAK,GACH,MAAbG,EAAKH,GADcA,KAO1B,YAAW,IAANA,GAAgBA,GAAK,EAClBG,EAAIuC,QAASF,GAAU,SAM/BC,GAHAA,EAAItC,EAAIwC,UAAW,EAAG3C,IAGhB0C,QAASF,GAAU,QAGzBrC,EAAMA,EAAK,GAAMsC,EAAItC,EAAIwC,UAAW3C,KE/CrC4C,GALS,ICyBT,IAAA5F,GAPA,SAAoBZ,GACnB,MAA0B,kBAAVA,GCjBbnB,GCDW4H,QAAQ9H,UAAUE,SDyBjC,IEvBIiD,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADAnB,GAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBP,IA0CrB,IAAA0B,GAhBA,SAAoBhC,GACnB,MAAsB,iBAAVA,IACNA,aAAiByG,UAGjB5F,GACGkB,GAAM/B,GAEoB,qBAAzB8B,GAAa9B,MClCpBiC,GAAc3B,GACd4B,GAAW9B,GAkCf,ICAI+B,GAAc7B,EACdoG,GDRJ,SAAoB1G,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICSxCkC,GAAWG,GAKfF,GAAauE,GAAW,cANNrG,IAOlB8B,GAAauE,GAAW,WAAYxE,IAKpC,IAAAvB,GAAiB+F,GCpCjB,IAAAC,GAPA,WACC,OAAO,IAAIC,SAAU,eAAd,ICFRC,GAL4B,iBAATC,KAAsBA,KAAO,KCKhDC,GAL8B,iBAAXC,OAAwBA,OAAS,6GCAhDzH,GAA0B,iBAAX0H,GAAwBA,GAAS,KAKpDC,OAAOC,QAAU5H,OCLbmH,GAAYpG,GAAuC2B,YACnDmF,GAAUhH,GACViH,GAAOhH,GACPiH,GAAMjF,GACNkF,sCAkDJ,IAAAhH,GA7BA,SAAoBoG,GACnB,GAAK9C,UAAUnB,OAAS,CACvB,IAAMgE,GAAWC,GAChB,MAAM,IAAI7G,UAAW,+DAA+D6G,EAAQ,MAE7F,GAAKA,EACJ,OAAOS,KAKT,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,MAAM,IAAItH,MAAO,uDC3CduH,GCOYlH,KDNZmH,GAAWD,GAAKE,UAAYF,GAAKE,SAASC,WER1CC,GAAaC,UCEbC,GAAKxH,GACLmH,GHUaA,GGTbG,GDCaA,GC6BjB,IAAAG,GAnBA,WACC,MAEe,mBAAPD,IAGe,iBAAfF,IAGa,mBAAbH,ICST,IAAAlH,GAPA,WACC,MAAO,2BCEJyH,GAAiB5H,GADHE,EAOL0H,GAAgB,SCjCR1H,MDsCrB,IAAAK,GAAiBqH,GEtCblG,GAAcxB,EAwClB,ICxCI2H,GD+BCC,MAAMD,QACNC,MAAMD,QARX,SAAkBjI,GACjB,MAAkC,mBAAzB8B,GAAa9B,IECvB,ICGImI,GDbJ,SAAuBnI,GACtB,OACW,OAAVA,GACiB,iBAAVA,GCQSM,EAOL6H,GAAc,oBFR3B,SAAmBC,GAClB,GAA0B,mBAAdA,EACX,MAAM,IAAItI,UAAW,sDAAwDsI,EAAY,MAE1F,OASA,SAAgBpI,GACf,IAAI0D,EACAE,EACJ,IAAMqE,GAASjI,GACd,OAAO,EAGR,GAAa,KADb0D,EAAM1D,EAAM0C,QAEX,OAAO,EAER,IAAMkB,EAAI,EAAGA,EAAIF,EAAKE,IACrB,IAAiC,IAA5BwE,EAAWpI,EAAO4D,IACtB,OAAO,EAGT,OAAO,GEpBuCyE,CAAUF,KAK1D,ICvCIA,GDuCaA,GCQjB,IC/CIrG,GAAcxB,EACdwH,GAAK1H,GAA0CkI,OAC/CC,GDyBJ,SAAmBvI,GAClB,OACCmI,GAAcnI,KAGbA,EAAMwI,WAELxI,EAAMyI,aAGgC,mBAA/BzI,EAAMyI,YAAYF,UACzBvI,EAAMyI,YAAYF,SAAUvI,KCmBhC,IAAAO,GAxBA,SAA0BY,GACzB,IAAIuH,EACAC,EACAC,EAEJ,IAAe,YADfD,EAAO7G,GAAaX,GAAI0H,MAAO,GAAI,KACC,UAATF,IAAqBxH,EAAEsH,YAAc,CAE/D,GAA0B,iBAD1BG,EAAOzH,EAAEsH,aACQE,KAChB,OAAOC,EAAKD,KAGb,GADAD,EAAQZ,GAAGgB,KAAMF,EAAK/J,YAErB,OAAO6J,EAAO,GAGhB,OAAKH,GAAUpH,GACP,SAEDwH,GCnDJI,GCkBkBzI,GDmCtB,IErDIyI,GDkBkBzI,GCAtB,ICFI0I,GHkBJ,SAAiB7H,GAChB,IAAI8H,EAGJ,OAAW,OAAN9H,EACG,OAKM,YAHd8H,SAAc9H,GAIN4H,GAAU5H,GAAI6C,cAEfiF,GG9BJ3J,GDNJ,SAAiB6B,GAChB,OAAO4H,GAAU5H,GAAI6C,eEZlBgF,GDec1I,KAOahB,GAAW0J,GCK1C,ICNArI,GDFA,SAAqBX,GAEpB,MAA6B,aAApBgJ,GAAQhJ,IErBd8I,GCFOI,OAAOvK,UAAUmK,KD0B5B,IEvBIhH,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADA8I,GAAKjJ,KAAMG,IACJ,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBP,IA0CrB,IC1CI6I,GAAU7I,GACV8I,GAAahJ,GACbgC,GAAW/B,EAAsC4B,YACjDoH,GDuBJ,SAAmBrJ,GAClB,MAAsB,iBAAVA,IACNA,aAAiBkJ,SAGjBrI,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MEDxB,ICjCIoF,GAAc9E,GACd6D,GAAY/D,GACZ8D,GAAY7D,GACZiG,GFsCJ,SAAkBvC,EAAKW,EAAQ4E,GAC9B,IAAMlH,GAAU2B,GACf,MAAM,IAAIjE,UAAW,wEAA0EiE,EAAM,MAEtG,GAAK3B,GAAUsC,GACdA,EAASyE,GAASzE,GAClBA,EAAS,IAAIwE,OAAQxE,EAAQ,UAEzB,IAAM2E,GAAU3E,GACpB,MAAM,IAAI5E,UAAW,+FAAiG4E,EAAS,MAEhI,IAAMtC,GAAUkH,KAAaF,GAAYE,GACxC,MAAM,IAAIxJ,UAAW,gGAAkGwJ,EAAS,MAEjI,OAAOvF,EAAIuC,QAAS5B,EAAQ4E,IEnDzBjE,GAAWC,GACX1C,GAAW4C,GAAsCvD,YACjDsH,GDoBJ,SAAc/G,GACb,OAAOD,KAAKgH,IAAK/G,IChBdgH,GAAoB,WACpBC,GAAoB,UACpBC,GAAiB,UACjBC,GAAuB,UACvBC,GAA0B,OAC1BC,GAAqB,QACrBC,GAAqB,gBAuEzB,IAAAC,GA1DA,SAAuBrE,GACtB,IAAIsE,EACArI,EACAsI,EAAIC,WAAYxE,EAAMG,KAC1B,IAAMR,GAAU4E,GAAM,CACrB,IAAMrH,GAAU8C,EAAMG,KACrB,MAAM,IAAI5F,MAAO,yCAA2C0B,GAG7DsI,EAAIvE,EAAMG,IAEX,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJjE,EAAMsI,EAAEE,cAAezE,EAAMK,WAC7B,MACD,IAAK,IACL,IAAK,IACJpE,EAAMsI,EAAEG,QAAS1E,EAAMK,WACvB,MACD,IAAK,IACL,IAAK,IACCwD,GAAKU,GAAM,OACfD,EAAStE,EAAMK,WACD,IACbiE,GAAU,GAEXrI,EAAMsI,EAAEE,cAAeH,IAEvBrI,EAAMsI,EAAEI,YAAa3E,EAAMK,WAEtBL,EAAMQ,YACXvE,EAAM2E,GAAS3E,EAAKmI,GAAoB,OACxCnI,EAAM2E,GAAS3E,EAAKkI,GAAoB,KACxClI,EAAM2E,GAAS3E,EAAKiI,GAAyB,KAE9C,MACD,QACC,MAAM,IAAI3J,MAAO,mCAAqCyF,EAAME,WAc7D,OAZAjE,EAAM2E,GAAS3E,EAAK6H,GAAmB,SACvC7H,EAAM2E,GAAS3E,EAAK8H,GAAmB,SAClC/D,EAAMQ,YACVvE,EAAM2E,GAAS3E,EAAK+H,GAAgB,OACpC/H,EAAM2E,GAAS3E,EAAKgI,GAAsB,SAEtCM,GAAK,GAAKvE,EAAMO,OACpBtE,EAAM+D,EAAMO,KAAOtE,GAEpBA,EAAQyD,GAAaM,EAAME,WAC1BzB,GAAWxC,GACXuC,GAAWvC,ICjFTmG,GAAK,6EA8DT,IC9DIlD,GAAStE,GA4Bb,IC5BI8B,GAAW9B,EAAsC2B,YACjDqI,GAAWlK,GACXgD,GAAQ/C,GACRkK,GAAgBlI,GAChBmI,GAAelF,GACfmF,GFOJ,SAAmB1G,GAClB,IAAI2G,EACAC,EACAC,EACAC,EACAnC,EAKJ,IAHAgC,EAAY,EACZE,EAAS,GACTlC,EAAQZ,GAAGgB,KAAM/E,GACT2E,IACPiC,EAAU5G,EAAI8E,MAAO6B,EAAW5C,GAAG4C,UAAYhC,EAAO,GAAIhG,SAC7CA,QACZkI,EAAOE,KAAMH,IAEdE,EAASE,EAAOrC,EAAOkC,EAAOlI,UAE7BkI,EAAOE,KAAMD,GAEdH,EAAY5C,GAAG4C,UACfhC,EAAQZ,GAAGgB,KAAM/E,GAMlB,OAJA4G,EAAU5G,EAAI8E,MAAO6B,IACRhI,QACZkI,EAAOE,KAAMH,GAEPC,EASP,SAASG,EAAOrC,GACf,MAAO,CACNsC,QAAatC,EAAO,GAAQ5C,SAAU4C,EAAO,GAAK,SAAO,EACzDuC,MAASvC,EAAO,GAChB3D,MAAS2D,EAAO,GAChBwC,UAA4B,MAAfxC,EAAO,GACpB3C,UAAa2C,EAAO,GACpB9C,UAAa8C,EAAO,MEhDnByC,GDQJ,SAAmBpH,EAAKgB,EAAOC,GAC9B,IAAIE,EAAMH,EAAQhB,EAAIrB,OACtB,OAAKwC,EAAM,EACHnB,EAERA,EAAM,EACLA,EAAMa,GAAQ,IAAKM,GACnBN,GAAQ,IAAKM,GAAQnB,GCdnBwB,GAAU6F,GAKVC,GAAexJ,OAAOwJ,aA+J1B,IAAA9K,GAzIA,SAAiBwD,GAChB,IAAI6G,EACAK,EACAvF,EACA4F,EACAC,EACA5J,EACAgC,EACAC,EACA4H,EAEJ,IAAMpJ,GAAU2B,GACf,MAAM,IAAIjE,UAAW,oDAAsDiE,EAAM,MAKlF,IAHA6G,EAASH,GAAU1G,GACnBpC,EAAM,GACNgC,EAAM,EACAC,EAAI,EAAGA,EAAIgH,EAAOlI,OAAQkB,IAE/B,GADA8B,EAAQkF,EAAQhH,GACXxB,GAAUsD,GACd/D,GAAO+D,MAEH,CAKJ,IAJKA,EAAMsF,UACVrH,EAAM+B,EAAMsF,SAEbC,EAAQvF,EAAMuF,MACRO,EAAI,EAAGA,EAAIP,EAAMvI,OAAQ8I,IAE9B,OADAF,EAAOL,EAAM9E,OAAQqF,IAErB,IAAK,IACJ9F,EAAMO,KAAO,IACb,MACD,IAAK,IACJP,EAAMO,KAAO,IACb,MACD,IAAK,IACJP,EAAMM,UAAW,EACjBN,EAAM+F,UAAW,EACjB,MACD,IAAK,IACJ/F,EAAM+F,UAAYnB,GAAUW,EAAO,KACnC,MACD,IAAK,IACJvF,EAAMQ,WAAY,EAClB,MACD,QACC,MAAM,IAAIjG,MAAO,iBAAmBqL,GAGtC,GAAqB,MAAhB5F,EAAMX,MAAgB,CAG1B,GAFAW,EAAMX,MAAQe,SAAUjC,UAAWF,GAAO,IAC1CA,GAAO,EACFP,GAAOsC,EAAMX,OACjB,MAAM,IAAIjF,UAAW,wCAA0C6D,EAAM,6BAA+B+B,EAAMX,MAAQ,MAE9GW,EAAMX,MAAQ,IAClBW,EAAMM,UAAW,EACjBN,EAAMX,OAASW,EAAMX,OAGvB,GAAyB,MAApBW,EAAMK,WAAqBL,EAAMwF,UAAY,CAGjD,GAFAxF,EAAMK,UAAYD,SAAUjC,UAAWF,GAAO,IAC9CA,GAAO,EACFP,GAAOsC,EAAMK,WACjB,MAAM,IAAIjG,UAAW,4CAA8C6D,EAAM,6BAA+B+B,EAAMK,UAAY,MAEtHL,EAAMK,UAAY,IACtBL,EAAMK,UAAY,EAClBL,EAAMwF,WAAY,GAIpB,OADAxF,EAAMG,IAAMhC,UAAWF,GACd+B,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAECF,EAAMwF,YACVxF,EAAM+F,UAAW,GAElB/F,EAAMG,IAAM0E,GAAe7E,GAC3B,MACD,IAAK,IAEJA,EAAMgG,SAAahG,EAAe,UAAKA,EAAMK,WAAa,EAC1D,MACD,IAAK,IAEJ,IAAM3C,GAAOsC,EAAMG,KAAQ,CAE1B,IADA0F,EAAMzF,SAAUJ,EAAMG,IAAK,KAChB,GAAK0F,EAAM,IACrB,MAAM,IAAItL,MAAO,kCAAoCyF,EAAMG,KAE5DH,EAAMG,IAAQzC,GAAOmI,GACpB1J,OAAQ6D,EAAMG,KACdwF,GAAcE,GAEhB,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEE7F,EAAMwF,YACXxF,EAAMK,UAAY,GAEnBL,EAAMG,IAAM2E,GAAc9E,GAC1B,MACD,QACC,MAAM,IAAIzF,MAAO,sBAAwByF,EAAME,WAG3CF,EAAMgG,UAAY,GAAKhG,EAAMG,IAAInD,OAASgD,EAAMgG,WACpDhG,EAAMG,IAAMH,EAAMG,IAAIU,UAAW,EAAGb,EAAMgG,WAEtChG,EAAM+F,SACV/F,EAAMG,IAAMN,GAASG,EAAMG,IAAKH,EAAMX,OAASW,EAAMK,UAAWL,EAAMM,UAC3DN,EAAMX,QACjBW,EAAMG,IAAMsF,GAAUzF,EAAMG,IAAKH,EAAMX,MAAOW,EAAMM,WAErDrE,GAAO+D,EAAMG,KAAO,GACpBlC,GAAO,EAGT,OAAOhC,GCrKJgK,GCeSrL,GD0Jb,IAAAC,GAhEA,WACC,IAAIqL,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/F,EACAmF,EACA5H,EASJ,IANAgI,EAAU/H,UAAW,GACrBgI,EAAShI,UAAW,GAGpBiI,GADAG,EAAQpI,UAAW,GADnBmI,GAHAD,EAAQlI,UAAW,IAGLnB,UAECA,OACfyJ,EAAMN,EACAjI,EAAI,EAAGA,EAAIoI,EAAOpI,IAAM,CAI7B,GAHAwI,EAAIL,EAAOnI,GACX4H,EAAI3H,UAAWD,EAAE,GAEH,WADdsI,EAAOD,EAAOrI,EAAEkI,IAEVN,EAAI,EACRA,EAAI,EACOA,GAAKY,IAChBZ,EAAIY,EAAI,QAEH,GAAc,SAATF,EACNV,EAAI,GACRA,GAAKY,GACI,GAEG,KADXZ,GAAKY,KAEJZ,GAAKY,GAGIZ,GAAKY,IAChBZ,GAAKY,IACKA,IACTZ,GAAKY,QAGD,GAAKZ,EAAI,GAAKA,GAAKY,EACzB,MAAM,IAAI5H,WAAYmH,GAAQ,6FAA8F/H,EAAG4H,KAEhInF,EAAIuF,EAAShI,IAGJ,GAAgB,IAAXiI,EACbM,GAAOX,EAAInF,EAEX8F,GAAOX,EAAInF,EAGb,OAAO8F,UElJM7L"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4c4dfff..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a547a19dfa0dddd2da0fa1765bbf8d7092b7b387 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 11:19:37 +0000 Subject: [PATCH 004/140] 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 | 62 +- benchmark/benchmark.js | 403 --- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 573 ----- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 -- manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 2689 +++++++++++++++++++++ stats_node.html | 2689 +++++++++++++++++++++ test/test.js | 403 --- 48 files changed, 5427 insertions(+), 5523 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 2b859da..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T21:26:39.493Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..319dc4e --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).sub2ind=r()}(this,(function(){"use strict";function t(t){var r=t.default;if("function"==typeof r){var e=function(){return r.apply(this,arguments)};e.prototype=r.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(t).forEach((function(r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})})),e}var r="function"==typeof Object.defineProperty?Object.defineProperty:null;var e=function(){try{return r({},"x",{}),!0}catch(t){return!1}},n=Object.defineProperty,o=Object.prototype,i=o.toString,u=o.__defineGetter__,a=o.__defineSetter__,f=o.__lookupGetter__,c=o.__lookupSetter__;var s=function(t,r,e){var n,s,l,h;if("object"!=typeof t||null===t||"[object Array]"===i.call(t))throw new TypeError("invalid argument. First argument must be an object. Value: `"+t+"`.");if("object"!=typeof e||null===e||"[object Array]"===i.call(e))throw new TypeError("invalid argument. Property descriptor must be an object. Value: `"+e+"`.");if((s="value"in e)&&(f.call(t,r)||c.call(t,r)?(n=t.__proto__,t.__proto__=o,delete t[r],t[r]=e.value,t.__proto__=n):t[r]=e.value),l="get"in e,h="set"in e,s&&(l||h))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return l&&u&&u.call(t,r,e.get),h&&a&&a.call(t,r,e.set),t},l=n,h=s,p=e()?l:h,y=p;var v=function(t,r,e){y(t,r,{configurable:!1,enumerable:!1,writable:!1,value:e})},g=v;var w=function(t){return"string"==typeof t};var d=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var b=function(){return d&&"symbol"==typeof Symbol.toStringTag},m=Object.prototype.toString,A=m;var E=function(t){return A.call(t)},_=Object.prototype.hasOwnProperty;var O=function(t,r){return null!=t&&_.call(t,r)},P="function"==typeof Symbol?Symbol.toStringTag:"",j=O,R=P,T=m;var U=E,S=function(t){var r,e,n;if(null==t)return T.call(t);e=t[R],r=j(t,R);try{t[R]=void 0}catch(r){return T.call(t)}return n=T.call(t),r?t[R]=e:delete t[R],n},I=b()?S:U,B=String.prototype.valueOf;var Y=I,x=function(t){try{return B.call(t),!0}catch(t){return!1}},C=b();var M=function(t){return"object"==typeof t&&(t instanceof String||(C?x(t):"[object String]"===Y(t)))},L=w,F=M;var D=g,N=function(t){return L(t)||F(t)},k=M;D(N,"isPrimitive",w),D(N,"isObject",k);var V=N,z=V.isPrimitive,G=/[-\/\\^$*+?.()|[\]{}]/g;var X=function(t){var r,e;if(!z(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");if("/"===t[0])for(e=t.length-1;e>=0&&"/"!==t[e];e--);return void 0===e||e<=0?t.replace(G,"\\$&"):(r=(r=t.substring(1,e)).replace(G,"\\$&"),t=t[0]+r+t.substring(e))},$=/./;var H=function(t){return"boolean"==typeof t},W=Boolean.prototype.toString;var q=I,J=function(t){try{return W.call(t),!0}catch(t){return!1}},Z=b();var K=function(t){return"object"==typeof t&&(t instanceof Boolean||(Z?J(t):"[object Boolean]"===q(t)))},Q=H,tt=K;var rt=g,et=function(t){return Q(t)||tt(t)},nt=K;rt(et,"isPrimitive",H),rt(et,"isObject",nt);var ot=et;var it=function(){return new Function("return this;")()},ut="object"==typeof self?self:null,at="object"==typeof window?window:null,ft="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},ct="object"==typeof ft?ft:null;module.exports=ct;var st=ot.isPrimitive,lt=it,ht=ut,pt=at,yt=t(Object.freeze({__proto__:null}));var vt=function(t){if(arguments.length){if(!st(t))throw new TypeError("invalid argument. Must provide a boolean primitive. Value: `"+t+"`.");if(t)return lt()}if(ht)return ht;if(pt)return pt;if(yt)return yt;throw new Error("unexpected error. Unable to resolve global object.")},gt=vt(),wt=gt.document&>.document.childNodes,dt=Int8Array,bt=$,mt=wt,At=dt;var Et=function(){return"function"==typeof bt||"object"==typeof At||"function"==typeof mt};var _t=function(){return/^\s*function\s*([^(]*)/i},Ot=_t;g(Ot,"REGEXP",_t());var Pt=Ot,jt=I;var Rt=Array.isArray?Array.isArray:function(t){return"[object Array]"===jt(t)},Tt=Rt;var Ut=function(t){return null!==t&&"object"==typeof t};g(Ut,"isObjectLikeArray",function(t){if("function"!=typeof t)throw new TypeError("invalid argument. Must provide a function. Value: `"+t+"`.");return function(r){var e,n;if(!Tt(r))return!1;if(0===(e=r.length))return!1;for(n=0;ndr&&br(t)},Ar=hr.isPrimitive,Er=mr;var _r=function(t){return Ar(t)&&Er(t)},Or=hr.isObject,Pr=mr;var jr=function(t){return Or(t)&&Pr(t.valueOf())},Rr=_r,Tr=jr;var Ur=g,Sr=function(t){return Rr(t)||Tr(t)},Ir=jr;Ur(Sr,"isPrimitive",_r),Ur(Sr,"isObject",Ir);var Br=Sr,Yr=Br.isPrimitive;var xr=function(t){return Yr(t)&&t>=0},Cr=Br.isObject;var Mr=function(t){return Cr(t)&&t.valueOf()>=0},Lr=xr,Fr=Mr;var Dr=g,Nr=function(t){return Lr(t)||Fr(t)},kr=Mr;Dr(Nr,"isPrimitive",xr),Dr(Nr,"isObject",kr);var Vr=Nr,zr=Object.getPrototypeOf;var Gr=function(t){return t.__proto__},Xr=I,$r=Gr;var Hr=function(t){var r=$r(t);return r||null===r?r:"[object Function]"===Xr(t.constructor)?t.constructor.prototype:t instanceof Object?Object.prototype:null},Wr=zr,qr=Hr,Jr=zt(Object.getPrototypeOf)?Wr:qr;var Zr=function(t){return null==t?null:(t=Object(t),Jr(t))},Kr=Zr,Qr=I;var te=function(t){if("object"!=typeof t||null===t)return!1;if(t instanceof Error)return!0;for(;t;){if("[object Error]"===Qr(t))return!0;t=Kr(t)}return!1};var re=function(){return/^\/((?:\\\/|[^\/])+)\/([imgy]*)$/},ee=re;g(ee,"REGEXP",re());var ne=V.isPrimitive,oe=ee;var ie=function(t){if(!ne(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");return(t=oe().exec(t))?new RegExp(t[1],t[2]):null};var ue=function(t){return t!=t},ae=hr.isPrimitive,fe=ue;var ce=function(t){return ae(t)&&fe(t)},se=hr.isObject,le=ue;var he=function(t){return se(t)&&le(t.valueOf())},pe=ce,ye=he;var ve=g,ge=function(t){return pe(t)||ye(t)},we=he;ve(ge,"isPrimitive",ce),ve(ge,"isObject",we);var de=ge,be=gr;var me=de,Ae=function(t){return"object"==typeof t&&null!==t&&"number"==typeof t.length&&be(t.length)&&t.length>=0&&t.length<=9007199254740991},Ee=V.isPrimitive,_e=Br.isPrimitive;var Oe=function(t,r,e){var n,o;if(!Ae(t)&&!Ee(t))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+t+"`.");if(0===(n=t.length))return-1;if(3===arguments.length){if(!_e(e))throw new TypeError("invalid argument. `fromIndex` must be an integer. Value: `"+e+"`.");if(e>=0){if(e>=n)return-1;o=e}else(o=n+e)<0&&(o=0)}else o=0;if(me(r)){for(;o=0&&r=0&&t.length<=4294967295&&Ge(t,"callee")&&!Xe(t,"callee")},qe=We,Je=je,Ze=Array.prototype.slice;var Ke=function(t){return qe(t)?Je(Ze.call(t)):Je(t)};var Qe=ze((function(){}),"prototype"),tn=!ze({toString:null},"toString");var rn,en=function(t){return t.constructor&&t.constructor.prototype===t},nn="undefined"==typeof window?void 0:window,on=O,un=Pe,an=kt,fn=en,cn=["console","external","frame","frameElement","frames","innerHeight","innerWidth","outerHeight","outerWidth","pageXOffset","pageYOffset","parent","scrollLeft","scrollTop","scrollX","scrollY","self","webkitIndexedDB","webkitStorageInfo","window"],sn=nn;rn=function(){var t;if("undefined"===an(sn))return!1;for(t in sn)try{-1===un(cn,t)&&on(sn,t)&&null!==sn[t]&&"object"===an(sn[t])&&fn(sn[t])}catch(t){return!0}return!1}();var ln="undefined"!=typeof window,hn=rn,pn=en,yn=ln;var vn=St,gn=O,wn=We,dn=Qe,bn=tn,mn=function(t){if(!1===yn&&!hn)return pn(t);try{return pn(t)}catch(t){return!1}},An=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"];var En=je,_n=Ke,On=function(t){var r,e,n,o,i,u,a;if(o=[],wn(t)){for(a=0;a0&&!gn(t,"0"))for(a=0;a!1})),Cn=[],Mn=[],Ln="undefined"!=typeof Uint8Array?Uint8Array:Array,Fn=!1;function Dn(){Fn=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=0,e=t.length;r>18&63]+Cn[o>>12&63]+Cn[o>>6&63]+Cn[63&o]);return i.join("")}function kn(t){var r;Fn||Dn();for(var e=t.length,n=e%3,o="",i=[],u=16383,a=0,f=e-n;af?f:a+u));return 1===n?(r=t[e-1],o+=Cn[r>>2],o+=Cn[r<<4&63],o+="=="):2===n&&(r=(t[e-2]<<8)+t[e-1],o+=Cn[r>>10],o+=Cn[r>>4&63],o+=Cn[r<<2&63],o+="="),i.push(o),i.join("")}function Vn(t,r,e,n,o){var i,u,a=8*o-n-1,f=(1<>1,s=-7,l=e?o-1:0,h=e?-1:1,p=t[r+l];for(l+=h,i=p&(1<<-s)-1,p>>=-s,s+=a;s>0;i=256*i+t[r+l],l+=h,s-=8);for(u=i&(1<<-s)-1,i>>=-s,s+=n;s>0;u=256*u+t[r+l],l+=h,s-=8);if(0===i)i=1-c;else{if(i===f)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),i-=c}return(p?-1:1)*u*Math.pow(2,i-n)}function zn(t,r,e,n,o,i){var u,a,f,c=8*i-o-1,s=(1<>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,y=n?1:-1,v=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,u=s):(u=Math.floor(Math.log(r)/Math.LN2),r*(f=Math.pow(2,-u))<1&&(u--,f*=2),(r+=u+l>=1?h/f:h*Math.pow(2,1-l))*f>=2&&(u++,f/=2),u+l>=s?(a=0,u=s):u+l>=1?(a=(r*f-1)*Math.pow(2,o),u+=l):(a=r*Math.pow(2,l-1)*Math.pow(2,o),u=0));o>=8;t[e+p]=255&a,p+=y,a/=256,o-=8);for(u=u<0;t[e+p]=255&u,p+=y,u/=256,c-=8);t[e+p-y]|=128*v}var Gn={}.toString,Xn=Array.isArray||function(t){return"[object Array]"==Gn.call(t)};qn.TYPED_ARRAY_SUPPORT=void 0===ft.TYPED_ARRAY_SUPPORT||ft.TYPED_ARRAY_SUPPORT;var $n=Hn();function Hn(){return qn.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Wn(t,r){if(Hn()=Hn())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Hn().toString(16)+" bytes");return 0|t}function ro(t){return!(null==t||!t._isBuffer)}function eo(t,r){if(ro(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return So(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return Io(t).length;default:if(n)return So(t).length;r=(""+r).toLowerCase(),n=!0}}function no(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return bo(this,r,e);case"utf8":case"utf-8":return yo(this,r,e);case"ascii":return go(this,r,e);case"latin1":case"binary":return wo(this,r,e);case"base64":return po(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return mo(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function oo(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function io(t,r,e,n,o){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0){if(!o)return-1;e=0}if("string"==typeof r&&(r=qn.from(r,n)),ro(r))return 0===r.length?-1:uo(t,r,e,n,o);if("number"==typeof r)return r&=255,qn.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):uo(t,[r],e,n,o);throw new TypeError("val must be string, number or Buffer")}function uo(t,r,e,n,o){var i,u=1,a=t.length,f=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,a/=2,f/=2,e/=2}function c(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(o){var s=-1;for(i=e;ia&&(e=a-f),i=e;i>=0;i--){for(var l=!0,h=0;ho&&(n=o):n=o;var i=r.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var u=0;u>8,o=e%256,i.push(o),i.push(n);return i}(r,t.length-e),t,e,n)}function po(t,r,e){return 0===r&&e===t.length?kn(t):kn(t.slice(r,e))}function yo(t,r,e){e=Math.min(t.length,e);for(var n=[],o=r;o239?4:c>223?3:c>191?2:1;if(o+l<=e)switch(l){case 1:c<128&&(s=c);break;case 2:128==(192&(i=t[o+1]))&&(f=(31&c)<<6|63&i)>127&&(s=f);break;case 3:i=t[o+1],u=t[o+2],128==(192&i)&&128==(192&u)&&(f=(15&c)<<12|(63&i)<<6|63&u)>2047&&(f<55296||f>57343)&&(s=f);break;case 4:i=t[o+1],u=t[o+2],a=t[o+3],128==(192&i)&&128==(192&u)&&128==(192&a)&&(f=(15&c)<<18|(63&i)<<12|(63&u)<<6|63&a)>65535&&f<1114112&&(s=f)}null===s?(s=65533,l=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=l}return function(t){var r=t.length;if(r<=vo)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),""},qn.prototype.compare=function(t,r,e,n,o){if(!ro(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),r<0||e>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&r>=e)return 0;if(n>=o)return-1;if(r>=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),a=Math.min(i,u),f=this.slice(n,o),c=t.slice(r,e),s=0;so)&&(e=o),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return ao(this,t,r,e);case"utf8":case"utf-8":return fo(this,t,r,e);case"ascii":return co(this,t,r,e);case"latin1":case"binary":return so(this,t,r,e);case"base64":return lo(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ho(this,t,r,e);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},qn.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var vo=4096;function go(t,r,e){var n="";e=Math.min(t.length,e);for(var o=r;on)&&(e=n);for(var o="",i=r;ie)throw new RangeError("Trying to access beyond buffer length")}function Eo(t,r,e,n,o,i){if(!ro(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>o||rt.length)throw new RangeError("Index out of range")}function _o(t,r,e,n){r<0&&(r=65535+r+1);for(var o=0,i=Math.min(t.length-e,2);o>>8*(n?o:1-o)}function Oo(t,r,e,n){r<0&&(r=4294967295+r+1);for(var o=0,i=Math.min(t.length-e,4);o>>8*(n?o:3-o)&255}function Po(t,r,e,n,o,i){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function jo(t,r,e,n,o){return o||Po(t,0,e,4),zn(t,r,e,n,23,4),e+4}function Ro(t,r,e,n,o){return o||Po(t,0,e,8),zn(t,r,e,n,52,8),e+8}qn.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(o*=256);)n+=this[t+--r]*o;return n},qn.prototype.readUInt8=function(t,r){return r||Ao(t,1,this.length),this[t]},qn.prototype.readUInt16LE=function(t,r){return r||Ao(t,2,this.length),this[t]|this[t+1]<<8},qn.prototype.readUInt16BE=function(t,r){return r||Ao(t,2,this.length),this[t]<<8|this[t+1]},qn.prototype.readUInt32LE=function(t,r){return r||Ao(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},qn.prototype.readUInt32BE=function(t,r){return r||Ao(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},qn.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||Ao(t,r,this.length);for(var n=this[t],o=1,i=0;++i=(o*=128)&&(n-=Math.pow(2,8*r)),n},qn.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||Ao(t,r,this.length);for(var n=r,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*r)),i},qn.prototype.readInt8=function(t,r){return r||Ao(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},qn.prototype.readInt16LE=function(t,r){r||Ao(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},qn.prototype.readInt16BE=function(t,r){r||Ao(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},qn.prototype.readInt32LE=function(t,r){return r||Ao(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},qn.prototype.readInt32BE=function(t,r){return r||Ao(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},qn.prototype.readFloatLE=function(t,r){return r||Ao(t,4,this.length),Vn(this,t,!0,23,4)},qn.prototype.readFloatBE=function(t,r){return r||Ao(t,4,this.length),Vn(this,t,!1,23,4)},qn.prototype.readDoubleLE=function(t,r){return r||Ao(t,8,this.length),Vn(this,t,!0,52,8)},qn.prototype.readDoubleBE=function(t,r){return r||Ao(t,8,this.length),Vn(this,t,!1,52,8)},qn.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||Eo(this,t,r,e,Math.pow(2,8*e)-1,0);var o=1,i=0;for(this[r]=255&t;++i=0&&(i*=256);)this[r+o]=t/i&255;return r+e},qn.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,1,255,0),qn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},qn.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,65535,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):_o(this,t,r,!0),r+2},qn.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,65535,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):_o(this,t,r,!1),r+2},qn.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,4294967295,0),qn.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):Oo(this,t,r,!0),r+4},qn.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,4294967295,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Oo(this,t,r,!1),r+4},qn.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Eo(this,t,r,e,o-1,-o)}var i=0,u=1,a=0;for(this[r]=255&t;++i>0)-a&255;return r+e},qn.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Eo(this,t,r,e,o-1,-o)}var i=e-1,u=1,a=0;for(this[r+i]=255&t;--i>=0&&(u*=256);)t<0&&0===a&&0!==this[r+i+1]&&(a=1),this[r+i]=(t/u>>0)-a&255;return r+e},qn.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,1,127,-128),qn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},qn.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,32767,-32768),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):_o(this,t,r,!0),r+2},qn.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,32767,-32768),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):_o(this,t,r,!1),r+2},qn.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,2147483647,-2147483648),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):Oo(this,t,r,!0),r+4},qn.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Oo(this,t,r,!1),r+4},qn.prototype.writeFloatLE=function(t,r,e){return jo(this,t,r,!0,e)},qn.prototype.writeFloatBE=function(t,r,e){return jo(this,t,r,!1,e)},qn.prototype.writeDoubleLE=function(t,r,e){return Ro(this,t,r,!0,e)},qn.prototype.writeDoubleBE=function(t,r,e){return Ro(this,t,r,!1,e)},qn.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--o)t[o+r]=this[o+e];else if(i<1e3||!qn.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(i=r;i55295&&e<57344){if(!o){if(e>56319){(r-=3)>-1&&i.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&i.push(239,191,189);continue}o=e;continue}if(e<56320){(r-=3)>-1&&i.push(239,191,189),o=e;continue}e=65536+(o-55296<<10|e-56320)}else o&&(r-=3)>-1&&i.push(239,191,189);if(o=null,e<128){if((r-=1)<0)break;i.push(e)}else if(e<2048){if((r-=2)<0)break;i.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;i.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;i.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return i}function Io(t){return function(t){var r,e,n,o,i,u;Fn||Dn();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[a-2]?2:"="===t[a-1]?1:0,u=new Ln(3*a/4-i),n=i>0?a-4:a;var f=0;for(r=0,e=0;r>16&255,u[f++]=o>>8&255,u[f++]=255&o;return 2===i?(o=Mn[t.charCodeAt(r)]<<2|Mn[t.charCodeAt(r+1)]>>4,u[f++]=255&o):1===i&&(o=Mn[t.charCodeAt(r)]<<10|Mn[t.charCodeAt(r+1)]<<4|Mn[t.charCodeAt(r+2)]>>2,u[f++]=o>>8&255,u[f++]=255&o),u}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(To,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Bo(t,r,e,n){for(var o=0;o=r.length||o>=t.length);++o)r[o+e]=t[o];return o}function Yo(t){return null!=t&&(!!t._isBuffer||xo(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&xo(t.slice(0,0))}(t))}function xo(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var Co=t(Object.freeze({__proto__:null,Buffer:qn,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),qn.alloc(+t)},isBuffer:Yo,kMaxLength:$n})).Buffer,Mo=function(){throw new Error("not implemented")},Lo=xn()?Co:Mo,Fo=zt(Lo.from),Do=Bt,No=Lo;var ko=function(t){if(!Do(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return No.from(t)},Vo=Bt,zo=Lo;var Go=function(t){if(!Vo(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return new zo(t)},Xo=Fo?ko:Go,$o=I,Ho="function"==typeof Int8Array;var Wo="function"==typeof Int8Array?Int8Array:null,qo=function(t){return Ho&&t instanceof Int8Array||"[object Int8Array]"===$o(t)},Jo=Wo;var Zo=function(){var t,r;if("function"!=typeof Jo)return!1;try{r=new Jo([1,3.14,-3.14,128]),t=qo(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-128===r[3]}catch(r){t=!1}return t};var Ko="function"==typeof Int8Array?Int8Array:void 0,Qo=function(){throw new Error("not implemented")},ti=Zo()?Ko:Qo,ri=I,ei="function"==typeof Uint8Array;var ni="function"==typeof Uint8Array?Uint8Array:null,oi=function(t){return ei&&t instanceof Uint8Array||"[object Uint8Array]"===ri(t)},ii=ni;var ui=function(){var t,r;if("function"!=typeof ii)return!1;try{r=new ii(r=[1,3.14,-3.14,256,257]),t=oi(r)&&1===r[0]&&3===r[1]&&253===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var ai="function"==typeof Uint8Array?Uint8Array:void 0,fi=function(){throw new Error("not implemented")},ci=ui()?ai:fi,si=I,li="function"==typeof Uint8ClampedArray;var hi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:null,pi=function(t){return li&&t instanceof Uint8ClampedArray||"[object Uint8ClampedArray]"===si(t)},yi=hi;var vi=function(){var t,r;if("function"!=typeof yi)return!1;try{r=new yi([-1,0,1,3.14,4.99,255,256]),t=pi(r)&&0===r[0]&&0===r[1]&&1===r[2]&&3===r[3]&&5===r[4]&&255===r[5]&&255===r[6]}catch(r){t=!1}return t};var gi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:void 0,wi=function(){throw new Error("not implemented")},di=vi()?gi:wi,bi=I,mi="function"==typeof Int16Array;var Ai="function"==typeof Int16Array?Int16Array:null,Ei=function(t){return mi&&t instanceof Int16Array||"[object Int16Array]"===bi(t)},_i=Ai;var Oi=function(){var t,r;if("function"!=typeof _i)return!1;try{r=new _i([1,3.14,-3.14,32768]),t=Ei(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-32768===r[3]}catch(r){t=!1}return t};var Pi="function"==typeof Int16Array?Int16Array:void 0,ji=function(){throw new Error("not implemented")},Ri=Oi()?Pi:ji,Ti=I,Ui="function"==typeof Uint16Array;var Si="function"==typeof Uint16Array?Uint16Array:null,Ii=function(t){return Ui&&t instanceof Uint16Array||"[object Uint16Array]"===Ti(t)},Bi=Si;var Yi=function(){var t,r;if("function"!=typeof Bi)return!1;try{r=new Bi(r=[1,3.14,-3.14,65536,65537]),t=Ii(r)&&1===r[0]&&3===r[1]&&65533===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var xi="function"==typeof Uint16Array?Uint16Array:void 0,Ci=function(){throw new Error("not implemented")},Mi=Yi()?xi:Ci,Li=I,Fi="function"==typeof Int32Array;var Di="function"==typeof Int32Array?Int32Array:null,Ni=function(t){return Fi&&t instanceof Int32Array||"[object Int32Array]"===Li(t)},ki=Di;var Vi=function(){var t,r;if("function"!=typeof ki)return!1;try{r=new ki([1,3.14,-3.14,2147483648]),t=Ni(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-2147483648===r[3]}catch(r){t=!1}return t};var zi="function"==typeof Int32Array?Int32Array:void 0,Gi=function(){throw new Error("not implemented")},Xi=Vi()?zi:Gi,$i=I,Hi="function"==typeof Uint32Array;var Wi="function"==typeof Uint32Array?Uint32Array:null,qi=function(t){return Hi&&t instanceof Uint32Array||"[object Uint32Array]"===$i(t)},Ji=Wi;var Zi=function(){var t,r;if("function"!=typeof Ji)return!1;try{r=new Ji(r=[1,3.14,-3.14,4294967296,4294967297]),t=qi(r)&&1===r[0]&&3===r[1]&&4294967293===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var Ki="function"==typeof Uint32Array?Uint32Array:void 0,Qi=function(){throw new Error("not implemented")},tu=Zi()?Ki:Qi,ru=I,eu="function"==typeof Float32Array;var nu="function"==typeof Float32Array?Float32Array:null,ou=function(t){return eu&&t instanceof Float32Array||"[object Float32Array]"===ru(t)},iu=pr,uu=nu;var au=function(){var t,r;if("function"!=typeof uu)return!1;try{r=new uu([1,3.14,-3.14,5e40]),t=ou(r)&&1===r[0]&&3.140000104904175===r[1]&&-3.140000104904175===r[2]&&r[3]===iu}catch(r){t=!1}return t};var fu="function"==typeof Float32Array?Float32Array:void 0,cu=function(){throw new Error("not implemented")},su=au()?fu:cu,lu=I,hu="function"==typeof Float64Array;var pu="function"==typeof Float64Array?Float64Array:null,yu=function(t){return hu&&t instanceof Float64Array||"[object Float64Array]"===lu(t)},vu=pu;var gu=function(){var t,r;if("function"!=typeof vu)return!1;try{r=new vu([1,3.14,-3.14,NaN]),t=yu(r)&&1===r[0]&&3.14===r[1]&&-3.14===r[2]&&r[3]!=r[3]}catch(r){t=!1}return t};var wu,du="function"==typeof Float64Array?Float64Array:void 0,bu=function(){throw new Error("not implemented")};wu=gu()?du:bu;var mu=ti,Au=ci,Eu=di,_u=Ri,Ou=Mi,Pu=Xi,ju=tu,Ru=su,Tu=wu;function Uu(t){return new mu(t)}function Su(t){return new Au(t)}function Iu(t){return new Eu(t)}function Bu(t){return new _u(t)}function Yu(t){return new Ou(t)}function xu(t){return new Pu(t)}function Cu(t){return new ju(t)}function Mu(t){return new Ru(t)}function Lu(t){return new Tu(t)}var Fu=O,Du=Rt,Nu=Bt,ku=te,Vu=kt,zu=ie,Gu=Pe,Xu=Pn,$u=Un,Hu=Yn,Wu=Zr,qu=p,Ju=Xo,Zu={int8array:Uu,uint8array:Su,uint8clampedarray:Iu,int16array:Bu,uint16array:Yu,int32array:xu,uint32array:Cu,float32array:Mu,float64array:Lu};function Ku(t,r,e,n,o){var i,u,a,f,c,s,l,h,p,y;if(o-=1,"object"!=typeof t||null===t)return t;if(Nu(t))return Ju(t);if(ku(t))return function(t){var r,e,n,o,i,u,a=[],f=[];for(i=new t.constructor(t.message),a.push(t),f.push(i),t.stack&&(i.stack=t.stack),t.code&&(i.code=t.code),t.errno&&(i.errno=t.errno),t.syscall&&(i.syscall=t.syscall),r=Xu(t),u=0;u0)for(i=a,y=0;y1){if(!ta(r))throw new TypeError("invalid argument. `level` must be a nonnegative integer. Value: `"+r+"`.");if(0===r)return t}else r=ra;return e=Qu(t)?new Array(t.length):{},ea(t,e,[t],[e],r)},oa=na,ia=Rt;var ua=function(t){return"object"==typeof t&&null!==t&&!ia(t)},aa=zt,fa=Zr,ca=O,sa=I,la=Object.prototype;var ha=function(t){var r;return!!ua(t)&&(!(r=fa(t))||!ca(t,"constructor")&&ca(r,"constructor")&&aa(r.constructor)&&"[object Function]"===sa(r.constructor)&&ca(r,"isPrototypeOf")&&aa(r.isPrototypeOf)&&(r===la||function(t){var r;for(r in t)if(!ca(t,r))return!1;return!0}(t)))},pa=ha,ya=O,va=V.isPrimitive;var ga={url:"https://stdlib.io/docs/api/latest/error-decoder.html",message:"Minified stdlib error code: {{code}}. Visit {{url}} for the full message."},wa=Kt,da=oa,ba=function(t,r){return pa(r)?ya(r,"url")&&(t.url=r.url,!va(t.url))?new TypeError("invalid option. `url` option must be a string primitive. Option: `"+t.url+"`."):ya(r,"message")&&(t.message=r.message,!va(t.message))?new TypeError("invalid option. `message` option must be a string primitive. Option: `"+t.message+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.")},ma=ga;var Aa=function(t){var r,e;if(r=da(ma),e=ba(r,t))throw e;return function(){var t,e,n=arguments[0],o=r.url+"?code="+n;for(e=1;e=f&&(s=f-1);else if("wrap"===u)s<0?(s+=f)<0&&0!==(s%=f)&&(s+=f):s>=f&&(s-=f)>=f&&(s%=f);else if(s<0||s>=f)throw new RangeError(_a("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",l,s));(c=t[l])<0&&0===r?a-=s*c:a+=s*c}return a}})); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..75b90f6 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/utils-define-property/lib/define_property.js","../node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js","../node_modules/@stdlib/utils-define-property/lib/builtin.js","../node_modules/@stdlib/utils-define-property/lib/polyfill.js","../node_modules/@stdlib/utils-define-property/lib/index.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/primitive.js","../node_modules/@stdlib/assert-has-symbol-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostring.js","../node_modules/@stdlib/utils-native-class/lib/native_class.js","../node_modules/@stdlib/assert-has-own-property/lib/main.js","../node_modules/@stdlib/assert-has-own-property/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostringtag.js","../node_modules/@stdlib/utils-native-class/lib/polyfill.js","../node_modules/@stdlib/utils-native-class/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/try2valueof.js","../node_modules/@stdlib/assert-is-string/lib/valueof.js","../node_modules/@stdlib/assert-is-string/lib/object.js","../node_modules/@stdlib/assert-is-string/lib/main.js","../node_modules/@stdlib/assert-is-string/lib/index.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/main.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/re.js","../node_modules/@stdlib/assert-is-boolean/lib/primitive.js","../node_modules/@stdlib/assert-is-boolean/lib/try2serialize.js","../node_modules/@stdlib/assert-is-boolean/lib/tostring.js","../node_modules/@stdlib/assert-is-boolean/lib/object.js","../node_modules/@stdlib/assert-is-boolean/lib/main.js","../node_modules/@stdlib/assert-is-boolean/lib/index.js","../node_modules/@stdlib/utils-global/lib/codegen.js","../node_modules/@stdlib/utils-global/lib/self.js","../node_modules/@stdlib/utils-global/lib/window.js","../node_modules/@stdlib/utils-global/lib/global.js","../node_modules/@stdlib/utils-global/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/nodelist.js","../node_modules/@stdlib/utils-global/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/typedarray.js","../node_modules/@stdlib/utils-type-of/lib/check.js","../node_modules/@stdlib/regexp-function-name/lib/main.js","../node_modules/@stdlib/regexp-function-name/lib/index.js","../node_modules/@stdlib/regexp-function-name/lib/regexp.js","../node_modules/@stdlib/assert-is-array/lib/main.js","../node_modules/@stdlib/assert-is-array/lib/index.js","../node_modules/@stdlib/assert-tools-array-function/lib/arrayfcn.js","../node_modules/@stdlib/assert-is-object-like/lib/main.js","../node_modules/@stdlib/assert-is-object-like/lib/index.js","../node_modules/@stdlib/assert-is-buffer/lib/main.js","../node_modules/@stdlib/assert-is-buffer/lib/index.js","../node_modules/@stdlib/utils-constructor-name/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/typeof.js","../node_modules/@stdlib/utils-constructor-name/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/polyfill.js","../node_modules/@stdlib/utils-type-of/lib/index.js","../node_modules/@stdlib/assert-is-function/lib/main.js","../node_modules/@stdlib/assert-is-function/lib/index.js","../node_modules/@stdlib/assert-is-regexp/lib/try2exec.js","../node_modules/@stdlib/assert-is-regexp/lib/exec.js","../node_modules/@stdlib/assert-is-regexp/lib/main.js","../node_modules/@stdlib/string-replace/lib/replace.js","../node_modules/@stdlib/string-replace/lib/index.js","../node_modules/@stdlib/assert-is-number/lib/primitive.js","../node_modules/@stdlib/number-ctor/lib/index.js","../node_modules/@stdlib/number-ctor/lib/number.js","../node_modules/@stdlib/assert-is-number/lib/try2serialize.js","../node_modules/@stdlib/assert-is-number/lib/tostring.js","../node_modules/@stdlib/assert-is-number/lib/object.js","../node_modules/@stdlib/assert-is-number/lib/main.js","../node_modules/@stdlib/assert-is-number/lib/index.js","../node_modules/@stdlib/constants-float64-pinf/lib/index.js","../node_modules/@stdlib/constants-float64-ninf/lib/index.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/is_integer.js","../node_modules/@stdlib/math-base-special-floor/lib/main.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-integer/lib/integer.js","../node_modules/@stdlib/assert-is-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-integer/lib/object.js","../node_modules/@stdlib/assert-is-integer/lib/main.js","../node_modules/@stdlib/assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/object.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/main.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/index.js","../node_modules/@stdlib/utils-get-prototype-of/lib/native.js","../node_modules/@stdlib/utils-get-prototype-of/lib/proto.js","../node_modules/@stdlib/utils-get-prototype-of/lib/polyfill.js","../node_modules/@stdlib/utils-get-prototype-of/lib/detect.js","../node_modules/@stdlib/utils-get-prototype-of/lib/get_prototype_of.js","../node_modules/@stdlib/utils-get-prototype-of/lib/index.js","../node_modules/@stdlib/assert-is-error/lib/main.js","../node_modules/@stdlib/assert-is-error/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/main.js","../node_modules/@stdlib/regexp-regexp/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/regexp.js","../node_modules/@stdlib/utils-regexp-from-string/lib/from_string.js","../node_modules/@stdlib/utils-regexp-from-string/lib/index.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/primitive.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-nan/lib/object.js","../node_modules/@stdlib/assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-collection/lib/main.js","../node_modules/@stdlib/utils-index-of/lib/index_of.js","../node_modules/@stdlib/constants-array-max-typed-array-length/lib/index.js","../node_modules/@stdlib/utils-index-of/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin.js","../node_modules/@stdlib/utils-keys/lib/has_arguments_bug.js","../node_modules/@stdlib/utils-keys/lib/has_builtin.js","../node_modules/@stdlib/assert-is-arguments/lib/main.js","../node_modules/@stdlib/assert-is-arguments/lib/detect.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/has_string_enumerability_bug.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/native.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/main.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/index.js","../node_modules/@stdlib/assert-is-arguments/lib/polyfill.js","../node_modules/@stdlib/assert-is-arguments/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin_wrapper.js","../node_modules/@stdlib/utils-noop/lib/noop.js","../node_modules/@stdlib/utils-keys/lib/has_enumerable_prototype_bug.js","../node_modules/@stdlib/utils-keys/lib/has_non_enumerable_properties_bug.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype.js","../node_modules/@stdlib/utils-keys/lib/has_automation_equality_bug.js","../node_modules/@stdlib/utils-keys/lib/window.js","../node_modules/@stdlib/utils-keys/lib/has_window.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype_wrapper.js","../node_modules/@stdlib/utils-keys/lib/polyfill.js","../node_modules/@stdlib/utils-keys/lib/main.js","../node_modules/@stdlib/utils-keys/lib/index.js","../node_modules/@stdlib/utils-property-names/lib/has_builtin.js","../node_modules/@stdlib/utils-property-names/lib/builtin.js","../node_modules/@stdlib/utils-property-names/lib/polyfill.js","../node_modules/@stdlib/utils-property-names/lib/index.js","../node_modules/@stdlib/utils-property-descriptor/lib/has_builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/polyfill.js","../node_modules/@stdlib/utils-property-descriptor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/polyfill.js","../node_modules/@stdlib/buffer-ctor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/buffer.js","../node_modules/@stdlib/buffer-from-buffer/lib/has_from.js","../node_modules/@stdlib/buffer-from-buffer/lib/main.js","../node_modules/@stdlib/buffer-from-buffer/lib/polyfill.js","../node_modules/@stdlib/buffer-from-buffer/lib/index.js","../node_modules/@stdlib/assert-is-int8array/lib/main.js","../node_modules/@stdlib/assert-has-int8array-support/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/main.js","../node_modules/@stdlib/constants-int8-min/lib/index.js","../node_modules/@stdlib/array-int8/lib/polyfill.js","../node_modules/@stdlib/array-int8/lib/index.js","../node_modules/@stdlib/array-int8/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8array/lib/main.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/main.js","../node_modules/@stdlib/array-uint8/lib/polyfill.js","../node_modules/@stdlib/array-uint8/lib/index.js","../node_modules/@stdlib/array-uint8/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8clampedarray/lib/main.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/main.js","../node_modules/@stdlib/array-uint8c/lib/polyfill.js","../node_modules/@stdlib/array-uint8c/lib/index.js","../node_modules/@stdlib/array-uint8c/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/index.js","../node_modules/@stdlib/assert-is-int16array/lib/main.js","../node_modules/@stdlib/assert-has-int16array-support/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/main.js","../node_modules/@stdlib/constants-int16-min/lib/index.js","../node_modules/@stdlib/array-int16/lib/polyfill.js","../node_modules/@stdlib/array-int16/lib/index.js","../node_modules/@stdlib/array-int16/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint16array/lib/main.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/main.js","../node_modules/@stdlib/array-uint16/lib/polyfill.js","../node_modules/@stdlib/array-uint16/lib/index.js","../node_modules/@stdlib/array-uint16/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/index.js","../node_modules/@stdlib/assert-is-int32array/lib/main.js","../node_modules/@stdlib/assert-has-int32array-support/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/main.js","../node_modules/@stdlib/constants-int32-min/lib/index.js","../node_modules/@stdlib/array-int32/lib/polyfill.js","../node_modules/@stdlib/array-int32/lib/index.js","../node_modules/@stdlib/array-int32/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint32array/lib/main.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/main.js","../node_modules/@stdlib/array-uint32/lib/polyfill.js","../node_modules/@stdlib/array-uint32/lib/index.js","../node_modules/@stdlib/array-uint32/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float32array/lib/main.js","../node_modules/@stdlib/assert-has-float32array-support/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/main.js","../node_modules/@stdlib/array-float32/lib/polyfill.js","../node_modules/@stdlib/array-float32/lib/index.js","../node_modules/@stdlib/array-float32/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float64array/lib/main.js","../node_modules/@stdlib/assert-has-float64array-support/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/main.js","../node_modules/@stdlib/array-float64/lib/polyfill.js","../node_modules/@stdlib/array-float64/lib/index.js","../node_modules/@stdlib/array-float64/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/index.js","../node_modules/@stdlib/utils-copy/lib/typed_arrays.js","../node_modules/@stdlib/utils-copy/lib/deep_copy.js","../node_modules/@stdlib/utils-copy/lib/copy.js","../node_modules/@stdlib/utils-copy/lib/index.js","../node_modules/@stdlib/assert-is-object/lib/main.js","../node_modules/@stdlib/assert-is-plain-object/lib/main.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/validate.js","../node_modules/@stdlib/assert-is-plain-object/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/factory.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\nvar main = ( typeof Object.defineProperty === 'function' ) ? Object.defineProperty : null;\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar defineProperty = require( './define_property.js' );\n\n\n// MAIN //\n\n/**\n* Tests for `Object.defineProperty` support.\n*\n* @private\n* @returns {boolean} boolean indicating if an environment has `Object.defineProperty` support\n*\n* @example\n* var bool = hasDefinePropertySupport();\n* // returns \n*/\nfunction hasDefinePropertySupport() {\n\t// Test basic support...\n\ttry {\n\t\tdefineProperty( {}, 'x', {} );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasDefinePropertySupport;\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// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @name defineProperty\n* @type {Function}\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nvar defineProperty = Object.defineProperty;\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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/* eslint-disable no-underscore-dangle, no-proto */\n\n'use strict';\n\n// VARIABLES //\n\nvar objectProtoype = Object.prototype;\nvar toStr = objectProtoype.toString;\nvar defineGetter = objectProtoype.__defineGetter__;\nvar defineSetter = objectProtoype.__defineSetter__;\nvar lookupGetter = objectProtoype.__lookupGetter__;\nvar lookupSetter = objectProtoype.__lookupSetter__;\n\n\n// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @param {Object} obj - object on which to define the property\n* @param {string} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nfunction defineProperty( obj, prop, descriptor ) {\n\tvar prototype;\n\tvar hasValue;\n\tvar hasGet;\n\tvar hasSet;\n\n\tif ( typeof obj !== 'object' || obj === null || toStr.call( obj ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an object. Value: `' + obj + '`.' );\n\t}\n\tif ( typeof descriptor !== 'object' || descriptor === null || toStr.call( descriptor ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. Property descriptor must be an object. Value: `' + descriptor + '`.' );\n\t}\n\thasValue = ( 'value' in descriptor );\n\tif ( hasValue ) {\n\t\tif (\n\t\t\tlookupGetter.call( obj, prop ) ||\n\t\t\tlookupSetter.call( obj, prop )\n\t\t) {\n\t\t\t// Override `__proto__` to avoid touching inherited accessors:\n\t\t\tprototype = obj.__proto__;\n\t\t\tobj.__proto__ = objectProtoype;\n\n\t\t\t// Delete property as existing getters/setters prevent assigning value to specified property:\n\t\t\tdelete obj[ prop ];\n\t\t\tobj[ prop ] = descriptor.value;\n\n\t\t\t// Restore original prototype:\n\t\t\tobj.__proto__ = prototype;\n\t\t} else {\n\t\t\tobj[ prop ] = descriptor.value;\n\t\t}\n\t}\n\thasGet = ( 'get' in descriptor );\n\thasSet = ( 'set' in descriptor );\n\n\tif ( hasValue && ( hasGet || hasSet ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.' );\n\t}\n\n\tif ( hasGet && defineGetter ) {\n\t\tdefineGetter.call( obj, prop, descriptor.get );\n\t}\n\tif ( hasSet && defineSetter ) {\n\t\tdefineSetter.call( obj, prop, descriptor.set );\n\t}\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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* Define (or modify) an object property.\n*\n* @module @stdlib/utils-define-property\n*\n* @example\n* var defineProperty = require( '@stdlib/utils-define-property' );\n*\n* var obj = {};\n* defineProperty( obj, 'foo', {\n* 'value': 'bar',\n* 'writable': false,\n* 'configurable': false,\n* 'enumerable': false\n* });\n* obj.foo = 'boop'; // => throws\n*/\n\n// MODULES //\n\nvar hasDefinePropertySupport = require( './has_define_property_support.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar defineProperty;\nif ( hasDefinePropertySupport() ) {\n\tdefineProperty = builtin;\n} else {\n\tdefineProperty = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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\nvar defineProperty = require( '@stdlib/utils-define-property' );\n\n\n// MAIN //\n\n/**\n* Defines a non-enumerable read-only property.\n*\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setNonEnumerableReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Define a non-enumerable read-only property.\n*\n* @module @stdlib/utils-define-nonenumerable-read-only-property\n*\n* @example\n* var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\n*\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\n\n// MODULES //\n\nvar setNonEnumerableReadOnly = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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// MAIN //\n\n/**\n* Tests for native `Symbol` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Symbol` support\n*\n* @example\n* var bool = hasSymbolSupport();\n* // returns \n*/\nfunction hasSymbolSupport() {\n\treturn (\n\t\ttypeof Symbol === 'function' &&\n\t\ttypeof Symbol( 'foo' ) === 'symbol'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasSymbolSupport;\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\nvar hasSymbols = require( '@stdlib/assert-has-symbol-support' );\n\n\n// VARIABLES //\n\nvar FLG = hasSymbols();\n\n\n// MAIN //\n\n/**\n* Tests for native `toStringTag` support.\n*\n* @returns {boolean} boolean indicating if an environment has `toStringTag` support\n*\n* @example\n* var bool = hasToStringTagSupport();\n* // returns \n*/\nfunction hasToStringTagSupport() {\n\treturn ( FLG && typeof Symbol.toStringTag === 'symbol' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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* Test for native `toStringTag` support.\n*\n* @module @stdlib/assert-has-tostringtag-support\n*\n* @example\n* var hasToStringTagSupport = require( '@stdlib/assert-has-tostringtag-support' );\n*\n* var bool = hasToStringTagSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasToStringTagSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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// MAIN //\n\nvar toStr = Object.prototype.toString;\n\n\n// EXPORTS //\n\nmodule.exports = toStr;\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\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification (via the internal property `[[Class]]`) of an object.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\treturn toStr.call( v );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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// FUNCTIONS //\n\nvar has = Object.prototype.hasOwnProperty;\n\n\n// MAIN //\n\n/**\n* Tests if an object has a specified property.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object has a specified property\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'bap' );\n* // returns false\n*/\nfunction hasOwnProp( value, property ) {\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\treturn has.call( value, property );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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* Test whether an object has a specified property.\n*\n* @module @stdlib/assert-has-own-property\n*\n* @example\n* var hasOwnProp = require( '@stdlib/assert-has-own-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* bool = hasOwnProp( beep, 'bop' );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasOwnProp = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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// MAIN //\n\nvar toStrTag = ( typeof Symbol === 'function' ) ? Symbol.toStringTag : '';\n\n\n// EXPORTS //\n\nmodule.exports = toStrTag;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar toStringTag = require( './tostringtag.js' );\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification of an object in environments supporting `Symbol.toStringTag`.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\tvar isOwn;\n\tvar tag;\n\tvar out;\n\n\tif ( v === null || v === void 0 ) {\n\t\treturn toStr.call( v );\n\t}\n\ttag = v[ toStringTag ];\n\tisOwn = hasOwnProp( v, toStringTag );\n\n\t// Attempt to override the `toStringTag` property. For built-ins having a `Symbol.toStringTag` property (e.g., `JSON`, `Math`, etc), the `Symbol.toStringTag` property is read-only (e.g., , so we need to wrap in a `try/catch`.\n\ttry {\n\t\tv[ toStringTag ] = void 0;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn toStr.call( v );\n\t}\n\tout = toStr.call( v );\n\n\tif ( isOwn ) {\n\t\tv[ toStringTag ] = tag;\n\t} else {\n\t\tdelete v[ toStringTag ];\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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* Return a string value indicating a specification defined classification of an object.\n*\n* @module @stdlib/utils-native-class\n*\n* @example\n* var nativeClass = require( '@stdlib/utils-native-class' );\n*\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* function Beep() {\n* return this;\n* }\n* str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\n\n// MODULES //\n\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar builtin = require( './native_class.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar nativeClass;\nif ( hasToStringTag() ) {\n\tnativeClass = polyfill;\n} else {\n\tnativeClass = builtin;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to extract a string value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a string can be extracted\n*/\nfunction test( value ) {\n\ttry {\n\t\tvalueOf.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar valueOf = String.prototype.valueOf; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2valueof.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string object\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns false\n*/\nfunction isString( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof String ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object String]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a string\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*/\nfunction isString( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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* Test if a value is a string.\n*\n* @module @stdlib/assert-is-string\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' );\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 5 );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isObject;\n*\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 'beep' );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isString = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isString, 'isPrimitive', isPrimitive );\nsetReadOnly( isString, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// VARIABLES //\n\nvar RE_CHARS = /[-\\/\\\\^$*+?.()|[\\]{}]/g; // eslint-disable-line no-useless-escape\n\n\n// MAIN //\n\n/**\n* Escapes a regular expression string.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} first argument must be a string primitive\n* @returns {string} escaped string\n*\n* @example\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\nfunction rescape( str ) {\n\tvar len;\n\tvar s;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Check if the string starts with a forward slash...\n\tif ( str[ 0 ] === '/' ) {\n\t\t// Find the last forward slash...\n\t\tlen = str.length;\n\t\tfor ( i = len-1; i >= 0; i-- ) {\n\t\t\tif ( str[ i ] === '/' ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:\n\tif ( i === void 0 || i <= 0 ) {\n\t\treturn str.replace( RE_CHARS, '\\\\$&' );\n\t}\n\t// We need to de-construct the string...\n\ts = str.substring( 1, i );\n\n\t// Only escape the characters between the `/`:\n\ts = s.replace( RE_CHARS, '\\\\$&' );\n\n\t// Reassemble:\n\tstr = str[ 0 ] + s + str.substring( i );\n\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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* Escape a regular expression string or pattern.\n*\n* @module @stdlib/utils-escape-regexp-string\n*\n* @example\n* var rescape = require( '@stdlib/utils-escape-regexp-string' );\n*\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\n\n// MODULES //\n\nvar rescape = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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\nvar RE = /./;\n\n\n// EXPORTS //\n\nmodule.exports = RE;\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* Tests if a value is a boolean primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean primitive\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns false\n*/\nfunction isBoolean( value ) {\n\treturn ( typeof value === 'boolean' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Boolean.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean object\n*\n* @example\n* var bool = isBoolean( true );\n* // returns false\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Boolean ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Boolean]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a boolean\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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* Test if a value is a boolean.\n*\n* @module @stdlib/assert-is-boolean\n*\n* @example\n* var isBoolean = require( '@stdlib/assert-is-boolean' );\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* // Use interface to check for boolean primitives...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( true ) );\n* // returns false\n*\n* @example\n* // Use interface to check for boolean objects...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isObject;\n*\n* var bool = isBoolean( true );\n* // returns false\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isBoolean = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isBoolean, 'isPrimitive', isPrimitive );\nsetReadOnly( isBoolean, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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// MAIN //\n\n/**\n* Returns the global object using code generation.\n*\n* @private\n* @returns {Object} global object\n*/\nfunction getGlobal() {\n\treturn new Function( 'return this;' )(); // eslint-disable-line no-new-func\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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// MAIN //\n\nvar obj = ( typeof self === 'object' ) ? self : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof window === 'object' ) ? window : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof global === 'object' ) ? global : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar getThis = require( './codegen.js' );\nvar Self = require( './self.js' );\nvar Win = require( './window.js' );\nvar Global = require( './global.js' );\n\n\n// MAIN //\n\n/**\n* Returns the global object.\n*\n* ## Notes\n*\n* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.\n*\n* @param {boolean} [codegen=false] - boolean indicating whether to use code generation to resolve the global object\n* @throws {TypeError} must provide a boolean\n* @throws {Error} unable to resolve global object\n* @returns {Object} global object\n*\n* @example\n* var g = getGlobal();\n* // returns {...}\n*/\nfunction getGlobal( codegen ) {\n\tif ( arguments.length ) {\n\t\tif ( !isBoolean( codegen ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Must provide a boolean primitive. Value: `'+codegen+'`.' );\n\t\t}\n\t\tif ( codegen ) {\n\t\t\treturn getThis();\n\t\t}\n\t\t// Fall through...\n\t}\n\t// Case: browsers and web workers\n\tif ( Self ) {\n\t\treturn Self;\n\t}\n\t// Case: browsers\n\tif ( Win ) {\n\t\treturn Win;\n\t}\n\t// Case: Node.js\n\tif ( Global ) {\n\t\treturn Global;\n\t}\n\t// Case: unknown\n\tthrow new Error( 'unexpected error. Unable to resolve global object.' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar getGlobal = require( '@stdlib/utils-global' );\n\n\n// MAIN //\n\nvar root = getGlobal();\nvar nodeList = root.document && root.document.childNodes;\n\n\n// EXPORTS //\n\nmodule.exports = nodeList;\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* Return the global object.\n*\n* @module @stdlib/utils-global\n*\n* @example\n* var getGlobal = require( '@stdlib/utils-global' );\n*\n* var g = getGlobal();\n* // returns {...}\n*/\n\n// MODULES //\n\nvar getGlobal = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar typedarray = Int8Array; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = typedarray;\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\nvar RE = require( './fixtures/re.js' );\nvar nodeList = require( './fixtures/nodelist.js' );\nvar typedarray = require( './fixtures/typedarray.js' );\n\n\n// MAIN //\n\n/**\n* Checks whether a polyfill is needed when using the `typeof` operator.\n*\n* @private\n* @returns {boolean} boolean indicating whether a polyfill is needed\n*/\nfunction check() {\n\tif (\n\t\t// Chrome 1-12 returns 'function' for regular expression instances (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof):\n\t\ttypeof RE === 'function' ||\n\n\t\t// Safari 8 returns 'object' for typed array and weak map constructors (underscore #1929):\n\t\ttypeof typedarray === 'object' ||\n\n\t\t// PhantomJS 1.9 returns 'function' for `NodeList` instances (underscore #2236):\n\t\ttypeof nodeList === 'function'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\nfunction reFunctionName() {\n\treturn /^\\s*function\\s*([^(]*)/i;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @module @stdlib/regexp-function-name\n*\n* @example\n* var reFunctionName = require( '@stdlib/regexp-function-name' );\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reFunctionName = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reFunctionName, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\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\nvar reFunctionName = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Captures everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* Regular expression: `/^\\s*function\\s*([^(]*)/i`\n*\n* - `/^\\s*`\n* - Match zero or more spaces at beginning\n*\n* - `function`\n* - Match the word `function`\n*\n* - `\\s*`\n* - Match zero or more spaces after the word `function`\n*\n* - `()`\n* - Capture\n*\n* - `[^(]*`\n* - Match anything except a left parenthesis `(` zero or more times\n*\n* - `/i`\n* - ignore case\n*\n* @constant\n* @type {RegExp}\n* @default /^\\s*function\\s*([^(]*)/i\n*/\nvar RE_FUNCTION_NAME = reFunctionName();\n\n\n// EXPORTS //\n\nmodule.exports = RE_FUNCTION_NAME;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar f;\n\n\n// FUNCTIONS //\n\n/**\n* Tests if a value is an array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an array\n*\n* @example\n* var bool = isArray( [] );\n* // returns true\n*\n* @example\n* var bool = isArray( {} );\n* // returns false\n*/\nfunction isArray( value ) {\n\treturn ( nativeClass( value ) === '[object Array]' );\n}\n\n\n// MAIN //\n\nif ( Array.isArray ) {\n\tf = Array.isArray;\n} else {\n\tf = isArray;\n}\n\n\n// EXPORTS //\n\nmodule.exports = f;\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* Test if a value is an array.\n*\n* @module @stdlib/assert-is-array\n*\n* @example\n* var isArray = require( '@stdlib/assert-is-array' );\n*\n* var bool = isArray( [] );\n* // returns true\n*\n* bool = isArray( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isArray = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isArray;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Returns a function which tests if every element in an array passes a test condition.\n*\n* @param {Function} predicate - function to apply\n* @throws {TypeError} must provide a function\n* @returns {Function} an array function\n*\n* @example\n* var isOdd = require( '@stdlib/assert-is-odd' );\n*\n* var arr1 = [ 1, 3, 5, 7 ];\n* var arr2 = [ 3, 5, 8 ];\n*\n* var validate = arrayfcn( isOdd );\n*\n* var bool = validate( arr1 );\n* // returns true\n*\n* bool = validate( arr2 );\n* // returns false\n*/\nfunction arrayfcn( predicate ) {\n\tif ( typeof predicate !== 'function' ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a function. Value: `' + predicate + '`.' );\n\t}\n\treturn every;\n\n\t/**\n\t* Tests if every element in an array passes a test condition.\n\t*\n\t* @private\n\t* @param {*} value - value to test\n\t* @returns {boolean} boolean indicating whether a value is an array for which all elements pass a test condition\n\t*/\n\tfunction every( value ) {\n\t\tvar len;\n\t\tvar i;\n\t\tif ( !isArray( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tlen = value.length;\n\t\tif ( len === 0 ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( predicate( value[ i ] ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayfcn;\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* Tests if a value is object-like.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is object-like\n*\n* @example\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( [] );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( null );\n* // returns false\n*/\nfunction isObjectLike( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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* Test if a value is object-like.\n*\n* @module @stdlib/assert-is-object-like\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' );\n*\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* bool = isObjectLike( [] );\n* // returns true\n*\n* bool = isObjectLike( null );\n* // returns false\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' ).isObjectLikeArray;\n*\n* var bool = isObjectLike( [ {}, [] ] );\n* // returns true\n*\n* bool = isObjectLike( [ {}, '3.0' ] );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar arrayfun = require( '@stdlib/assert-tools-array-function' );\nvar isObjectLike = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( isObjectLike, 'isObjectLikeArray', arrayfun( isObjectLike ) );\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Buffer instance.\n*\n* @param {*} value - value to validate\n* @returns {boolean} boolean indicating if a value is a Buffer instance\n*\n* @example\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( new Buffer( [1,2,3,4] ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( {} );\n* // returns false\n*\n* @example\n* var v = isBuffer( [] );\n* // returns false\n*/\nfunction isBuffer( value ) {\n\treturn (\n\t\tisObjectLike( value ) &&\n\t\t(\n\t\t\t// eslint-disable-next-line no-underscore-dangle\n\t\t\tvalue._isBuffer || // for envs missing Object.prototype.constructor (e.g., Safari 5-7)\n\t\t\t(\n\t\t\t\tvalue.constructor &&\n\n\t\t\t\t// WARNING: `typeof` is not a foolproof check, as certain envs consider RegExp and NodeList instances to be functions\n\t\t\t\ttypeof value.constructor.isBuffer === 'function' &&\n\t\t\t\tvalue.constructor.isBuffer( value )\n\t\t\t)\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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* Test if a value is a Buffer instance.\n*\n* @module @stdlib/assert-is-buffer\n*\n* @example\n* var isBuffer = require( '@stdlib/assert-is-buffer' );\n*\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* v = isBuffer( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isBuffer = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar RE = require( '@stdlib/regexp-function-name' ).REGEXP;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\n\n\n// MAIN //\n\n/**\n* Determines the name of a value's constructor.\n*\n* @param {*} v - input value\n* @returns {string} name of a value's constructor\n*\n* @example\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* @example\n* var v = constructorName( 5 );\n* // returns 'Number'\n*\n* @example\n* var v = constructorName( null );\n* // returns 'Null'\n*\n* @example\n* var v = constructorName( undefined );\n* // returns 'Undefined'\n*\n* @example\n* var v = constructorName( function noop() {} );\n* // returns 'Function'\n*/\nfunction constructorName( v ) {\n\tvar match;\n\tvar name;\n\tvar ctor;\n\tname = nativeClass( v ).slice( 8, -1 );\n\tif ( (name === 'Object' || name === 'Error') && v.constructor ) {\n\t\tctor = v.constructor;\n\t\tif ( typeof ctor.name === 'string' ) {\n\t\t\treturn ctor.name;\n\t\t}\n\t\tmatch = RE.exec( ctor.toString() );\n\t\tif ( match ) {\n\t\t\treturn match[ 1 ];\n\t\t}\n\t}\n\tif ( isBuffer( v ) ) {\n\t\treturn 'Buffer';\n\t}\n\treturn name;\n}\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// NOTES //\n\n/*\n* Built-in `typeof` operator behavior:\n*\n* ```text\n* typeof null => 'object'\n* typeof undefined => 'undefined'\n* typeof 'a' => 'string'\n* typeof 5 => 'number'\n* typeof NaN => 'number'\n* typeof true => 'boolean'\n* typeof false => 'boolean'\n* typeof {} => 'object'\n* typeof [] => 'object'\n* typeof function foo(){} => 'function'\n* typeof function* foo(){} => 'object'\n* typeof Symbol() => 'symbol'\n* ```\n*\n*/\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\tvar type;\n\n\t// Address `typeof null` => `object` (see http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null):\n\tif ( v === null ) {\n\t\treturn 'null';\n\t}\n\ttype = typeof v;\n\n\t// If the `typeof` operator returned something other than `object`, we are done. Otherwise, we need to check for an internal class name or search for a constructor.\n\tif ( type === 'object' ) {\n\t\treturn ctorName( v ).toLowerCase();\n\t}\n\treturn type;\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine the name of a value's constructor.\n*\n* @module @stdlib/utils-constructor-name\n*\n* @example\n* var constructorName = require( '@stdlib/utils-constructor-name' );\n*\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* v = constructorName( {} );\n* // returns 'Object'\n*\n* v = constructorName( true );\n* // returns 'Boolean'\n*/\n\n// MODULES //\n\nvar constructorName = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\treturn ctorName( v ).toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine a value's type.\n*\n* @module @stdlib/utils-type-of\n*\n* @example\n* var typeOf = require( '@stdlib/utils-type-of' );\n*\n* var str = typeOf( 'a' );\n* // returns 'string'\n*\n* str = typeOf( 5 );\n* // returns 'number'\n*/\n\n// MODULES //\n\nvar usePolyfill = require( './check.js' );\nvar typeOf = require( './typeof.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main = ( usePolyfill() ) ? polyfill : typeOf;\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar typeOf = require( '@stdlib/utils-type-of' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a function.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a function\n*\n* @example\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\nfunction isFunction( value ) {\n\t// Note: cannot use `typeof` directly, as various browser engines incorrectly return `'function'` when operating on non-function objects, such as regular expressions and NodeLists.\n\treturn ( typeOf( value ) === 'function' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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* Test if a value is a function.\n*\n* @module @stdlib/assert-is-function\n*\n* @example\n* var isFunction = require( '@stdlib/assert-is-function' );\n*\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\n\n// MODULES //\n\nvar isFunction = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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\nvar exec = require( './exec.js' );\n\n\n// MAIN //\n\n/**\n* Attempts to call a `RegExp` method.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if able to call a `RegExp` method\n*/\nfunction test( value ) {\n\ttry {\n\t\texec.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar exec = RegExp.prototype.exec; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = exec;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2exec.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a regular expression.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a regular expression\n*\n* @example\n* var bool = isRegExp( /\\.+/ );\n* // returns true\n*\n* @example\n* var bool = isRegExp( {} );\n* // returns false\n*/\nfunction isRegExp( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof RegExp ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object RegExp]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isRegExp;\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\nvar rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument argument must be a string primitive or regular expression\n* @throws {TypeError} third argument must be a string primitive or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive or regular expression. Value: `' + search + '`.' );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( 'invalid argument. Third argument must be a string primitive or replacement function. Value: `' + newval + '`.' );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Constructor which returns a `Number` object.\n*\n* @module @stdlib/number-ctor\n*\n* @example\n* var Number = require( '@stdlib/number-ctor' );\n*\n* var v = new Number( 10.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar Number = require( './number.js' );\n\n\n// EXPORTS //\n\nmodule.exports = Number;\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// EXPORTS //\n\nmodule.exports = Number; // eslint-disable-line stdlib/require-globals\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Number.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar Number = require( '@stdlib/number-ctor' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\nfunction isNumber( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Number ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Number]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a number\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( null );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Test if a value is a number.\n*\n* @module @stdlib/assert-is-number\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' );\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( null );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isObject;\n*\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNumber, 'isPrimitive', isPrimitive );\nsetReadOnly( isNumber, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Double-precision floating-point positive infinity.\n*\n* @module @stdlib/constants-float64-pinf\n* @type {number}\n*\n* @example\n* var FLOAT64_PINF = require( '@stdlib/constants-float64-pinf' );\n* // returns Infinity\n*/\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point positive infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point positive infinity has the bit sequence\n*\n* ```binarystring\n* 0 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.POSITIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_PINF = Number.POSITIVE_INFINITY; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_PINF;\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* Double-precision floating-point negative infinity.\n*\n* @module @stdlib/constants-float64-ninf\n* @type {number}\n*\n* @example\n* var FLOAT64_NINF = require( '@stdlib/constants-float64-ninf' );\n* // returns -Infinity\n*/\n\n// MODULES //\n\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point negative infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point negative infinity has the bit sequence\n*\n* ```binarystring\n* 1 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.NEGATIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_NINF = Number.NEGATIVE_INFINITY;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_NINF;\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\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Tests if a finite double-precision floating-point number is an integer.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\treturn (floor(x) === x);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// TODO: implementation (?)\n\n/**\n* Rounds a double-precision floating-point number toward negative infinity.\n*\n* @param {number} x - input value\n* @returns {number} rounded value\n*\n* @example\n* var v = floor( -4.2 );\n* // returns -5.0\n*\n* @example\n* var v = floor( 9.99999 );\n* // returns 9.0\n*\n* @example\n* var v = floor( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = floor( NaN );\n* // returns NaN\n*/\nvar floor = Math.floor; // eslint-disable-line stdlib/no-builtin-math\n\n\n// EXPORTS //\n\nmodule.exports = floor;\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* Test if a finite double-precision floating-point number is an integer.\n*\n* @module @stdlib/math-base-assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/math-base-assert-is-integer' );\n*\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* bool = isInteger( 3.14 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isInteger = require( './is_integer.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar isInt = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests if a number primitive is an integer value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a number primitive is an integer value\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tvalue < PINF &&\n\t\tvalue > NINF &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having an integer value\n*\n* @example\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having an integer value\n*\n* @example\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an integer\n*\n* @example\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isInteger( -3.14 );\n* // returns false\n*\n* @example\n* var bool = isInteger( null );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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* Test if a value is an integer.\n*\n* @module @stdlib/assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/assert-is-integer' );\n*\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isInteger( -3.14 );\n* // returns false\n*\n* bool = isInteger( null );\n* // returns false\n*\n* @example\n* // Use interface to check for integer primitives...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n*\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*\n* @example\n* // Use interface to check for integer objects...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n*\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue.valueOf() >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a nonnegative integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a nonnegative integer\n*\n* @example\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( null );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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* Test if a value is a nonnegative integer.\n*\n* @module @stdlib/assert-is-nonnegative-integer\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' );\n*\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* bool = isNonNegativeInteger( null );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isObject;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNonNegativeInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isNonNegativeInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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// MAIN //\n\nvar getProto = Object.getPrototypeOf;\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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* Returns the value of the `__proto__` property.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {*} value of `__proto__` property\n*/\nfunction getProto( obj ) {\n\t// eslint-disable-next-line no-proto\n\treturn obj.__proto__;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar getProto = require( './proto.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {(Object|null)} prototype\n*/\nfunction getPrototypeOf( obj ) {\n\tvar proto = getProto( obj );\n\tif ( proto || proto === null ) {\n\t\treturn proto;\n\t}\n\tif ( nativeClass( obj.constructor ) === '[object Function]' ) {\n\t\t// May break if the constructor has been tampered with...\n\t\treturn obj.constructor.prototype;\n\t}\n\tif ( obj instanceof Object ) {\n\t\treturn Object.prototype;\n\t}\n\t// Return `null` for objects created via `Object.create( null )`. Also return `null` for cross-realm objects on browsers that lack `__proto__` support, such as IE < 11.\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar builtin = require( './native.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar getProto;\nif ( isFunction( Object.getPrototypeOf ) ) {\n\tgetProto = builtin;\n} else {\n\tgetProto = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar getProto = require( './detect.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @param {*} value - input value\n* @returns {(Object|null)} prototype\n*\n* @example\n* var proto = getPrototypeOf( {} );\n* // returns {}\n*/\nfunction getPrototypeOf( value ) {\n\tif (\n\t\tvalue === null ||\n\t\tvalue === void 0\n\t) {\n\t\treturn null;\n\t}\n\t// In order to ensure consistent ES5/ES6 behavior, cast input value to an object (strings, numbers, booleans); ES5 `Object.getPrototypeOf` throws when provided primitives and ES6 `Object.getPrototypeOf` casts:\n\tvalue = Object( value );\n\n\treturn getProto( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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* Return the prototype of a provided object.\n*\n* @module @stdlib/utils-get-prototype-of\n*\n* @example\n* var getPrototype = require( '@stdlib/utils-get-prototype-of' );\n*\n* var proto = getPrototype( {} );\n* // returns {}\n*/\n\n// MODULES //\n\nvar getPrototype = require( './get_prototype_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getPrototype;\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\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an `Error` object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `Error` object\n*\n* @example\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isError( {} );\n* // returns false\n*/\nfunction isError( value ) {\n\tif ( typeof value !== 'object' || value === null ) {\n\t\treturn false;\n\t}\n\t// Check for `Error` objects from the same realm (same Node.js `vm` or same `Window` object)...\n\tif ( value instanceof Error ) {\n\t\treturn true;\n\t}\n\t// Walk the prototype tree until we find an object having the desired native class...\n\twhile ( value ) {\n\t\tif ( nativeClass( value ) === '[object Error]' ) {\n\t\t\treturn true;\n\t\t}\n\t\tvalue = getPrototypeOf( value );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isError;\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* Test if a value is an `Error` object.\n*\n* @module @stdlib/assert-is-error\n*\n* @example\n* var isError = require( '@stdlib/assert-is-error' );\n*\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* bool = isError( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isError = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isError;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to parse a regular expression string.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*/\nfunction reRegExp() {\n\treturn /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/; // eslint-disable-line no-useless-escape\n}\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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* Return a regular expression to parse a regular expression string.\n*\n* @module @stdlib/regexp-regexp\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var parts = RE_REGEXP.exec( '/^.*$/ig' );\n* // returns [ '/^.*$/ig', '^.*$', 'ig', 'index': 0, 'input': '/^.*$/ig' ]\n*/\n\n// MAIN //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reRegExp = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reRegExp, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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\nvar reRegExp = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Matches parts of a regular expression string.\n*\n* Regular expression: `/^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/`\n*\n* - `/^\\/`\n* - match a string that begins with a `/`\n*\n* - `()`\n* - capture\n*\n* - `(?:)+`\n* - capture, but do not remember, a group of characters which occur one or more times\n*\n* - `\\\\\\/`\n* - match the literal `\\/`\n*\n* - `|`\n* - OR\n*\n* - `[^\\/]`\n* - anything which is not the literal `\\/`\n*\n* - `\\/`\n* - match the literal `/`\n*\n* - `([imgy]*)`\n* - capture any characters matching `imgy` occurring zero or more times\n*\n* - `$/`\n* - string end\n*\n*\n* @constant\n* @type {RegExp}\n* @default /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/\n*/\nvar RE_REGEXP = reRegExp();\n\n\n// EXPORTS //\n\nmodule.exports = RE_REGEXP;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar reRegExp = require( '@stdlib/regexp-regexp' );\n\n\n// MAIN //\n\n/**\n* Parses a regular expression string and returns a new regular expression.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} must provide a regular expression string\n* @returns {(RegExp|null)} regular expression or null\n*\n* @example\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\nfunction reFromString( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Capture the regular expression pattern and any flags:\n\tstr = reRegExp().exec( str );\n\n\t// Create a new regular expression:\n\treturn ( str ) ? new RegExp( str[1], str[2] ) : null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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* Create a regular expression from a regular expression string.\n*\n* @module @stdlib/utils-regexp-from-string\n*\n* @example\n* var reFromString = require( '@stdlib/utils-regexp-from-string' );\n*\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\n\n// MODULES //\n\nvar reFromString = require( './from_string.js' );\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is `NaN`.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 7.0 );\n* // returns false\n*/\nfunction isnan( x ) {\n\treturn ( x !== x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a `NaN` number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a `NaN` number primitive\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a double-precision floating-point numeric value is `NaN`.\n*\n* @module @stdlib/math-base-assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/math-base-assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 7.0 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isnan = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a value of `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a value of `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( null );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a value is `NaN`.\n*\n* @module @stdlib/assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( null );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isObject;\n*\n* var bool = isnan( NaN );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isnan = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isnan, 'isPrimitive', isPrimitive );\nsetReadOnly( isnan, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a collection.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is a collection\n*\n* @example\n* var bool = isCollection( [] );\n* // returns true\n*\n* @example\n* var bool = isCollection( {} );\n* // returns false\n*/\nfunction isCollection( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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\nvar isnan = require( '@stdlib/assert-is-nan' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Returns the first index at which a given element can be found.\n*\n* @param {ArrayLike} arr - array-like object\n* @param {*} searchElement - element to find\n* @param {integer} [fromIndex] - starting index (if negative, the start index is determined relative to last element)\n* @throws {TypeError} must provide an array-like object\n* @throws {TypeError} `fromIndex` must be an integer\n* @returns {integer} index or -1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 5 );\n* // returns -1\n*\n* @example\n* // Using a `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* @example\n* // `fromIndex` which exceeds `array` length:\n* var arr = [ 1, 2, 3, 4, 2, 5 ];\n* var idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* @example\n* // Negative `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* var idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* @example\n* // Negative `fromIndex` exceeding input `array` length:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* @example\n* // Array-like objects:\n* var str = 'bebop';\n* var idx = indexOf( str, 'o' );\n* // returns 3\n*/\nfunction indexOf( arr, searchElement, fromIndex ) {\n\tvar len;\n\tvar i;\n\tif ( !isCollection( arr ) && !isString( arr ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array-like object. Value: `' + arr + '`.' );\n\t}\n\tlen = arr.length;\n\tif ( len === 0 ) {\n\t\treturn -1;\n\t}\n\tif ( arguments.length === 3 ) {\n\t\tif ( !isInteger( fromIndex ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `fromIndex` must be an integer. Value: `' + fromIndex + '`.' );\n\t\t}\n\t\tif ( fromIndex >= 0 ) {\n\t\t\tif ( fromIndex >= len ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\ti = fromIndex;\n\t\t} else {\n\t\t\ti = len + fromIndex;\n\t\t\tif ( i < 0 ) {\n\t\t\t\ti = 0;\n\t\t\t}\n\t\t}\n\t} else {\n\t\ti = 0;\n\t}\n\t// Check for `NaN`...\n\tif ( isnan( searchElement ) ) {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( isnan( arr[i] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( arr[ i ] === searchElement ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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* Maximum length of a typed array.\n*\n* @module @stdlib/constants-array-max-typed-array-length\n*\n* @example\n* var MAX_TYPED_ARRAY_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n* // returns 9007199254740991\n*/\n\n// MAIN //\n\n/**\n* Maximum length of a typed array.\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n*/\nvar MAX_TYPED_ARRAY_LENGTH = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = MAX_TYPED_ARRAY_LENGTH;\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* Return the first index at which a given element can be found.\n*\n* @module @stdlib/utils-index-of\n*\n* @example\n* var indexOf = require( '@stdlib/utils-index-of' );\n*\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* arr = [ 4, 3, 2, 1 ];\n* idx = indexOf( arr, 5 );\n* // returns -1\n*\n* // Using a `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* // `fromIndex` which exceeds `array` length:\n* arr = [ 1, 2, 3, 4, 2, 5 ];\n* idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* // Negative `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* // Negative `fromIndex` exceeding input `array` length:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* // Array-like objects:\n* var str = 'bebop';\n* idx = indexOf( str, 'o' );\n* // returns 3\n*/\n\n// MODULES //\n\nvar indexOf = require( './index_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.keys()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\treturn Object.keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar keys = require( './builtin.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests the built-in `Object.keys()` implementation when provided `arguments`.\n*\n* @private\n* @returns {boolean} boolean indicating whether the built-in implementation returns the expected number of keys\n*/\nfunction test() {\n\treturn ( keys( arguments ) || '' ).length !== 2;\n}\n\n\n// MAIN //\n\n/**\n* Tests whether the built-in `Object.keys()` implementation supports providing `arguments` as an input value.\n*\n* ## Notes\n*\n* - Safari 5.0 does **not** support `arguments` as an input value.\n*\n* @private\n* @returns {boolean} boolean indicating whether a built-in implementation supports `arguments`\n*/\nfunction check() {\n\treturn test( 1, 2 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\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// MAIN //\n\nvar bool = ( typeof Object.keys !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn ( nativeClass( value ) === '[object Arguments]' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( './main.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment returns the expected internal class of the `arguments` object.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment behaves as expected\n*\n* @example\n* var bool = detect();\n* // returns \n*/\nfunction detect() {\n\treturn isArguments( arguments );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnum = require( './native.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment has a bug where String indices are not detected as \"enumerable\" properties. Observed in Node v0.10.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment has the bug\n*/\nfunction detect() {\n\treturn !isEnum.call( 'beep', '0' );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @private\n* @name isEnumerableProperty\n* @type {Function}\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nvar isEnumerableProperty = Object.prototype.propertyIsEnumerable;\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar isString = require( '@stdlib/assert-is-string' );\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isEnum = require( './native.js' );\nvar hasStringEnumBug = require( './has_string_enumerability_bug.js' );\n\n\n// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nfunction isEnumerableProperty( value, property ) {\n\tvar bool;\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\tbool = isEnum.call( value, property );\n\tif ( !bool && hasStringEnumBug && isString( value ) ) {\n\t\t// Note: we only check for indices, as properties attached to a `String` object are properly detected as enumerable above.\n\t\tproperty = +property;\n\t\treturn (\n\t\t\t!isnan( property ) &&\n\t\t\tisInteger( property ) &&\n\t\t\tproperty >= 0 &&\n\t\t\tproperty < value.length\n\t\t);\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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* Test whether an object's own property is enumerable.\n*\n* @module @stdlib/assert-is-enumerable-property\n*\n* @example\n* var isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\n\n// MODULES //\n\nvar isEnumerableProperty = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-uint32-max' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object' &&\n\t\t!isArray( value ) &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH &&\n\t\thasOwnProp( value, 'callee' ) &&\n\t\t!isEnumerableProperty( value, 'callee' )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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* Test if a value is an `arguments` object.\n*\n* @module @stdlib/assert-is-arguments\n*\n* @example\n* var isArguments = require( '@stdlib/assert-is-arguments' );\n*\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* bool = isArguments( [] );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasArgumentsClass = require( './detect.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar isArguments;\nif ( hasArgumentsClass ) {\n\tisArguments = main;\n} else {\n\tisArguments = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar builtin = require( './builtin.js' );\n\n\n// VARIABLES //\n\nvar slice = Array.prototype.slice;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tif ( isArguments( value ) ) {\n\t\treturn builtin( slice.call( value ) );\n\t}\n\treturn builtin( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* No operation.\n*\n* @example\n* noop();\n* // ...does nothing.\n*/\nfunction noop() {\n\t// Empty function...\n}\n\n\n// EXPORTS //\n\nmodule.exports = noop;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar noop = require( '@stdlib/utils-noop' );\n\n\n// MAIN //\n\n// Note: certain environments treat an object's prototype as enumerable, which, as a matter of convention, it shouldn't be...\nvar bool = isEnumerableProperty( noop, 'prototype' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n\n\n// VARIABLES //\n\nvar obj = {\n\t'toString': null\n};\n\n\n// MAIN //\n\n// Note: certain environments don't allow enumeration of overwritten properties which are considered non-enumerable...\nvar bool = !isEnumerableProperty( obj, 'toString' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests whether a value equals the prototype of its constructor.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction isConstructorPrototype( value ) {\n\treturn ( value.constructor && value.constructor.prototype === value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isConstructorPrototype;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar EXCLUDED_KEYS = require( './excluded_keys.json' );\nvar win = require( './window.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Determines whether an environment throws when comparing to the prototype of a value's constructor (e.g., [IE9][1]).\n*\n* [1]: https://stackoverflow.com/questions/7688070/why-is-comparing-the-constructor-property-of-two-windows-unreliable\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment is buggy\n*/\nfunction check() {\n\tvar k;\n\tif ( typeOf( win ) === 'undefined' ) {\n\t\treturn false;\n\t}\n\tfor ( k in win ) { // eslint-disable-line guard-for-in\n\t\ttry {\n\t\t\tif (\n\t\t\t\tindexOf( EXCLUDED_KEYS, k ) === -1 &&\n\t\t\t\thasOwnProp( win, k ) &&\n\t\t\t\twin[ k ] !== null &&\n\t\t\t\ttypeOf( win[ k ] ) === 'object'\n\t\t\t) {\n\t\t\t\tisConstructorPrototype( win[ k ] );\n\t\t\t}\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// MAIN //\n\nbool = check();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\nvar w = ( typeof window === 'undefined' ) ? void 0 : window;\n\n\n// EXPORTS //\n\nmodule.exports = w;\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// MAIN //\n\nvar bool = ( typeof window !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar hasAutomationEqualityBug = require( './has_automation_equality_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar HAS_WINDOW = require( './has_window.js' );\n\n\n// MAIN //\n\n/**\n* Wraps the test for constructor prototype equality to accommodate buggy environments (e.g., environments which throw when testing equality).\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction wrapper( value ) {\n\tif ( HAS_WINDOW === false && !hasAutomationEqualityBug ) {\n\t\treturn isConstructorPrototype( value );\n\t}\n\ttry {\n\t\treturn isConstructorPrototype( value );\n\t} catch ( error ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = wrapper;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar HAS_ENUM_PROTO_BUG = require( './has_enumerable_prototype_bug.js' );\nvar HAS_NON_ENUM_PROPS_BUG = require( './has_non_enumerable_properties_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype_wrapper.js' );\nvar NON_ENUMERABLE = require( './non_enumerable.json' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tvar skipConstructor;\n\tvar skipPrototype;\n\tvar isFcn;\n\tvar out;\n\tvar k;\n\tvar p;\n\tvar i;\n\n\tout = [];\n\tif ( isArguments( value ) ) {\n\t\t// Account for environments which treat `arguments` differently...\n\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\tout.push( i.toString() );\n\t\t}\n\t\t// Note: yes, we are precluding the `arguments` array-like object from having other enumerable properties; however, this should (1) be very rare and (2) not be encouraged (e.g., doing something like `arguments.a = 'b'`; in certain engines directly manipulating the `arguments` value results in automatic de-optimization).\n\t\treturn out;\n\t}\n\tif ( typeof value === 'string' ) {\n\t\t// Account for environments which do not treat string character indices as \"own\" properties...\n\t\tif ( value.length > 0 && !hasOwnProp( value, '0' ) ) {\n\t\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\t\tout.push( i.toString() );\n\t\t\t}\n\t\t}\n\t} else {\n\t\tisFcn = ( typeof value === 'function' );\n\t\tif ( isFcn === false && !isObjectLike( value ) ) {\n\t\t\treturn out;\n\t\t}\n\t\tskipPrototype = ( HAS_ENUM_PROTO_BUG && isFcn );\n\t}\n\tfor ( k in value ) {\n\t\tif ( !( skipPrototype && k === 'prototype' ) && hasOwnProp( value, k ) ) {\n\t\t\tout.push( String( k ) );\n\t\t}\n\t}\n\tif ( HAS_NON_ENUM_PROPS_BUG ) {\n\t\tskipConstructor = isConstructorPrototype( value );\n\t\tfor ( i = 0; i < NON_ENUMERABLE.length; i++ ) {\n\t\t\tp = NON_ENUMERABLE[ i ];\n\t\t\tif ( !( skipConstructor && p === 'constructor' ) && hasOwnProp( value, p ) ) {\n\t\t\t\tout.push( String( p ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar hasArgumentsBug = require( './has_arguments_bug.js' );\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar wrapper = require( './builtin_wrapper.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @name keys\n* @type {Function}\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nvar keys;\nif ( HAS_BUILTIN ) {\n\tif ( hasArgumentsBug() ) {\n\t\tkeys = wrapper;\n\t} else {\n\t\tkeys = builtin;\n\t}\n} else {\n\tkeys = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* Return an array of an object's own enumerable property names.\n*\n* @module @stdlib/utils-keys\n*\n* @example\n* var keys = require( '@stdlib/utils-keys' );\n*\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\n\n// MODULES //\n\nvar keys = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyNames !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyNames = Object.getOwnPropertyNames;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn propertyNames( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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\nvar keys = require( '@stdlib/utils-keys' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n* - In environments lacking support for `Object.getOwnPropertyNames()`, property descriptors are unavailable, and thus all properties can be safely assumed to be enumerable. Hence, we can defer to calling `Object.keys`, which retrieves all own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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* Return an array of an object's own enumerable and non-enumerable property names.\n*\n* @module @stdlib/utils-property-names\n*\n* @example\n* var getOwnPropertyNames = require( '@stdlib/utils-property-names' );\n*\n* var keys = getOwnPropertyNames({\n* 'foo': 'bar',\n* 'beep': 'boop'\n* });\n* // e.g., returns [ 'foo', 'beep' ]\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyDescriptor !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyDescriptor = Object.getOwnPropertyDescriptor;\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tvar desc;\n\tif ( value === null || value === void 0 ) {\n\t\treturn null;\n\t}\n\tdesc = propertyDescriptor( value, property );\n\treturn ( desc === void 0 ) ? null : desc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n* - In environments lacking `Object.getOwnPropertyDescriptor()` support, property descriptors do not exist. In non-supporting environment, if an object has a provided property, this function returns a descriptor object equivalent to that returned in a supporting environment; otherwise, the function returns `null`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tif ( hasOwnProp( value, property ) ) {\n\t\treturn {\n\t\t\t'configurable': true,\n\t\t\t'enumerable': true,\n\t\t\t'writable': true,\n\t\t\t'value': value[ property ]\n\t\t};\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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* Return a property descriptor for an object's own property.\n*\n* @module @stdlib/utils-property-descriptor\n*\n* @example\n* var getOwnPropertyDescriptor = require( '@stdlib/utils-property-descriptor' );\n*\n* var obj = {\n* 'foo': 'bar',\n* 'beep': 'boop'\n* };\n*\n* var keys = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':'bar'}\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// TODO: write (browser) polyfill\n\n// MAIN //\n\n/**\n* Buffer constructor.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Buffer constructor.\n*\n* @module @stdlib/buffer-ctor\n*\n* @example\n* var ctor = require( '@stdlib/buffer-ctor' );\n*\n* var b = new ctor( [ 1, 2, 3, 4 ] );\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\nvar main = require( './buffer.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasNodeBufferSupport() ) {\n\tctor = main;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = require( 'buffer' ).Buffer; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\nvar bool = isFunction( Buffer.from );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn Buffer.from( buffer );\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn new Buffer( buffer ); // eslint-disable-line no-buffer-constructor\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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* Copy buffer data to a new `Buffer` instance.\n*\n* @module @stdlib/buffer-from-buffer\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n* var copyBuffer = require( '@stdlib/buffer-from-buffer' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = copyBuffer( b1 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFrom = require( './has_from.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar copyBuffer;\nif ( hasFrom ) {\n\tcopyBuffer = main;\n} else {\n\tcopyBuffer = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt8Array = ( typeof Int8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int8Array\n*\n* @example\n* var bool = isInt8Array( new Int8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt8Array( [] );\n* // returns false\n*/\nfunction isInt8Array( value ) {\n\treturn (\n\t\t( hasInt8Array && value instanceof Int8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt8Array;\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// MAIN //\n\nvar main = ( typeof Int8Array === 'function' ) ? Int8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt8Array = require( '@stdlib/assert-is-int8array' );\nvar INT8_MAX = require( '@stdlib/constants-int8-max' );\nvar INT8_MIN = require( '@stdlib/constants-int8-min' );\nvar GlobalInt8Array = require( './int8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int8Array` support\n*\n* @example\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\nfunction hasInt8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt8Array( [ 1, 3.14, -3.14, INT8_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT8_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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* Minimum signed 8-bit integer.\n*\n* @module @stdlib/constants-int8-min\n* @type {integer32}\n*\n* @example\n* var INT8_MIN = require( '@stdlib/constants-int8-min' );\n* // returns -128\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 8-bit integer.\n*\n* ## Notes\n*\n* The number is given by\n*\n* ```tex\n* -(2^{7})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -128\n*/\nvar INT8_MIN = -128|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT8_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int8\n*\n* @example\n* var ctor = require( '@stdlib/array-int8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\nvar builtin = require( './int8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int8Array === 'function' ) ? Int8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int8Array` support.\n*\n* @module @stdlib/assert-has-int8array-support\n*\n* @example\n* var hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\n*\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8Array = ( typeof Uint8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8Array\n*\n* @example\n* var bool = isUint8Array( new Uint8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8Array( [] );\n* // returns false\n*/\nfunction isUint8Array( value ) {\n\treturn (\n\t\t( hasUint8Array && value instanceof Uint8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8Array;\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// MAIN //\n\nvar main = ( typeof Uint8Array === 'function' ) ? Uint8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8Array = require( '@stdlib/assert-is-uint8array' );\nvar UINT8_MAX = require( '@stdlib/constants-uint8-max' );\nvar GlobalUint8Array = require( './uint8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8Array` support\n*\n* @example\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\nfunction hasUint8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT8_MAX+1, UINT8_MAX+2 ];\n\t\tarr = new GlobalUint8Array( arr );\n\t\tbool = (\n\t\t\tisUint8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT8_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint8\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\nvar builtin = require( './uint8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8Array === 'function' ) ? Uint8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8Array` support.\n*\n* @module @stdlib/assert-has-uint8array-support\n*\n* @example\n* var hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\n*\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8ClampedArray = ( typeof Uint8ClampedArray === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8ClampedArray.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8ClampedArray\n*\n* @example\n* var bool = isUint8ClampedArray( new Uint8ClampedArray( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8ClampedArray( [] );\n* // returns false\n*/\nfunction isUint8ClampedArray( value ) {\n\treturn (\n\t\t( hasUint8ClampedArray && value instanceof Uint8ClampedArray ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8ClampedArray]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8ClampedArray;\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// MAIN //\n\nvar main = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8ClampedArray = require( '@stdlib/assert-is-uint8clampedarray' );\nvar GlobalUint8ClampedArray = require( './uint8clampedarray.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8ClampedArray` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8ClampedArray` support\n*\n* @example\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\nfunction hasUint8ClampedArraySupport() { // eslint-disable-line id-length\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8ClampedArray !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalUint8ClampedArray( [ -1, 0, 1, 3.14, 4.99, 255, 256 ] );\n\t\tbool = (\n\t\t\tisUint8ClampedArray( arr ) &&\n\t\t\tarr[ 0 ] === 0 && // clamped\n\t\t\tarr[ 1 ] === 0 &&\n\t\t\tarr[ 2 ] === 1 &&\n\t\t\tarr[ 3 ] === 3 && // round to nearest\n\t\t\tarr[ 4 ] === 5 && // round to nearest\n\t\t\tarr[ 5 ] === 255 &&\n\t\t\tarr[ 6 ] === 255 // clamped\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @module @stdlib/array-uint8c\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8c' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' ); // eslint-disable-line id-length\nvar builtin = require( './uint8clampedarray.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ClampedArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8ClampedArray` support.\n*\n* @module @stdlib/assert-has-uint8clampedarray-support\n*\n* @example\n* var hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' );\n*\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt16Array = ( typeof Int16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int16Array\n*\n* @example\n* var bool = isInt16Array( new Int16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt16Array( [] );\n* // returns false\n*/\nfunction isInt16Array( value ) {\n\treturn (\n\t\t( hasInt16Array && value instanceof Int16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt16Array;\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// MAIN //\n\nvar main = ( typeof Int16Array === 'function' ) ? Int16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt16Array = require( '@stdlib/assert-is-int16array' );\nvar INT16_MAX = require( '@stdlib/constants-int16-max' );\nvar INT16_MIN = require( '@stdlib/constants-int16-min' );\nvar GlobalInt16Array = require( './int16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int16Array` support\n*\n* @example\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\nfunction hasInt16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt16Array( [ 1, 3.14, -3.14, INT16_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT16_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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* Minimum signed 16-bit integer.\n*\n* @module @stdlib/constants-int16-min\n* @type {integer32}\n*\n* @example\n* var INT16_MIN = require( '@stdlib/constants-int16-min' );\n* // returns -32768\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 16-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{15})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 1000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -32768\n*/\nvar INT16_MIN = -32768|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT16_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int16\n*\n* @example\n* var ctor = require( '@stdlib/array-int16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\nvar builtin = require( './int16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int16Array === 'function' ) ? Int16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int16Array` support.\n*\n* @module @stdlib/assert-has-int16array-support\n*\n* @example\n* var hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\n*\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint16Array = ( typeof Uint16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint16Array\n*\n* @example\n* var bool = isUint16Array( new Uint16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint16Array( [] );\n* // returns false\n*/\nfunction isUint16Array( value ) {\n\treturn (\n\t\t( hasUint16Array && value instanceof Uint16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint16Array;\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// MAIN //\n\nvar main = ( typeof Uint16Array === 'function' ) ? Uint16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint16Array = require( '@stdlib/assert-is-uint16array' );\nvar UINT16_MAX = require( '@stdlib/constants-uint16-max' );\nvar GlobalUint16Array = require( './uint16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint16Array` support\n*\n* @example\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\nfunction hasUint16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT16_MAX+1, UINT16_MAX+2 ];\n\t\tarr = new GlobalUint16Array( arr );\n\t\tbool = (\n\t\t\tisUint16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT16_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 16-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint16\n*\n* @example\n* var ctor = require( '@stdlib/array-uint16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\nvar builtin = require( './uint16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint16Array === 'function' ) ? Uint16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint16Array` support.\n*\n* @module @stdlib/assert-has-uint16array-support\n*\n* @example\n* var hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\n*\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt32Array = ( typeof Int32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int32Array\n*\n* @example\n* var bool = isInt32Array( new Int32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt32Array( [] );\n* // returns false\n*/\nfunction isInt32Array( value ) {\n\treturn (\n\t\t( hasInt32Array && value instanceof Int32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt32Array;\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// MAIN //\n\nvar main = ( typeof Int32Array === 'function' ) ? Int32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt32Array = require( '@stdlib/assert-is-int32array' );\nvar INT32_MAX = require( '@stdlib/constants-int32-max' );\nvar INT32_MIN = require( '@stdlib/constants-int32-min' );\nvar GlobalInt32Array = require( './int32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int32Array` support\n*\n* @example\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\nfunction hasInt32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt32Array( [ 1, 3.14, -3.14, INT32_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT32_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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* Minimum signed 32-bit integer.\n*\n* @module @stdlib/constants-int32-min\n* @type {integer32}\n*\n* @example\n* var INT32_MIN = require( '@stdlib/constants-int32-min' );\n* // returns -2147483648\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 32-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{31})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -2147483648\n*/\nvar INT32_MIN = -2147483648|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT32_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int32\n*\n* @example\n* var ctor = require( '@stdlib/array-int32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\nvar builtin = require( './int32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int32Array === 'function' ) ? Int32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int32Array` support.\n*\n* @module @stdlib/assert-has-int32array-support\n*\n* @example\n* var hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\n*\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint32Array = ( typeof Uint32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint32Array\n*\n* @example\n* var bool = isUint32Array( new Uint32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint32Array( [] );\n* // returns false\n*/\nfunction isUint32Array( value ) {\n\treturn (\n\t\t( hasUint32Array && value instanceof Uint32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint32Array;\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// MAIN //\n\nvar main = ( typeof Uint32Array === 'function' ) ? Uint32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint32Array = require( '@stdlib/assert-is-uint32array' );\nvar UINT32_MAX = require( '@stdlib/constants-uint32-max' );\nvar GlobalUint32Array = require( './uint32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint32Array` support\n*\n* @example\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\nfunction hasUint32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT32_MAX+1, UINT32_MAX+2 ];\n\t\tarr = new GlobalUint32Array( arr );\n\t\tbool = (\n\t\t\tisUint32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT32_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 32-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint32\n*\n* @example\n* var ctor = require( '@stdlib/array-uint32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\nvar builtin = require( './uint32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint32Array === 'function' ) ? Uint32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint32Array` support.\n*\n* @module @stdlib/assert-has-uint32array-support\n*\n* @example\n* var hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\n*\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat32Array = ( typeof Float32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float32Array\n*\n* @example\n* var bool = isFloat32Array( new Float32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat32Array( [] );\n* // returns false\n*/\nfunction isFloat32Array( value ) {\n\treturn (\n\t\t( hasFloat32Array && value instanceof Float32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat32Array;\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// MAIN //\n\nvar main = ( typeof Float32Array === 'function' ) ? Float32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat32Array = require( '@stdlib/assert-is-float32array' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar GlobalFloat32Array = require( './float32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float32Array` support\n*\n* @example\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\nfunction hasFloat32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat32Array( [ 1.0, 3.14, -3.14, 5.0e40 ] );\n\t\tbool = (\n\t\t\tisFloat32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.140000104904175 &&\n\t\t\tarr[ 2 ] === -3.140000104904175 &&\n\t\t\tarr[ 3 ] === PINF\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of single-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float32\n*\n* @example\n* var ctor = require( '@stdlib/array-float32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\nvar builtin = require( './float32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float32Array === 'function' ) ? Float32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float32Array` support.\n*\n* @module @stdlib/assert-has-float32array-support\n*\n* @example\n* var hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\n*\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat64Array = ( typeof Float64Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float64Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float64Array\n*\n* @example\n* var bool = isFloat64Array( new Float64Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat64Array( [] );\n* // returns false\n*/\nfunction isFloat64Array( value ) {\n\treturn (\n\t\t( hasFloat64Array && value instanceof Float64Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float64Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat64Array;\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// MAIN //\n\nvar main = ( typeof Float64Array === 'function' ) ? Float64Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat64Array = require( '@stdlib/assert-is-float64array' );\nvar GlobalFloat64Array = require( './float64array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float64Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float64Array` support\n*\n* @example\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\nfunction hasFloat64ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat64Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat64Array( [ 1.0, 3.14, -3.14, NaN ] );\n\t\tbool = (\n\t\t\tisFloat64Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.14 &&\n\t\t\tarr[ 2 ] === -3.14 &&\n\t\t\tarr[ 3 ] !== arr[ 3 ]\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of double-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float64\n*\n* @example\n* var ctor = require( '@stdlib/array-float64' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\nvar builtin = require( './float64array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat64ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float64Array === 'function' ) ? Float64Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float64Array` support.\n*\n* @module @stdlib/assert-has-float64array-support\n*\n* @example\n* var hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\n*\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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\nvar Int8Array = require( '@stdlib/array-int8' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar Uint8ClampedArray = require( '@stdlib/array-uint8c' );\nvar Int16Array = require( '@stdlib/array-int16' );\nvar Uint16Array = require( '@stdlib/array-uint16' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar Uint32Array = require( '@stdlib/array-uint32' );\nvar Float32Array = require( '@stdlib/array-float32' );\nvar Float64Array = require( '@stdlib/array-float64' );\n\n\n// VARIABLES //\n\nvar hash;\n\n\n// FUNCTIONS //\n\n/**\n* Copies an `Int8Array`.\n*\n* @private\n* @param {Int8Array} arr - array to copy\n* @returns {Int8Array} new array\n*/\nfunction int8array( arr ) {\n\treturn new Int8Array( arr );\n}\n\n/**\n* Copies a `Uint8Array`.\n*\n* @private\n* @param {Uint8Array} arr - array to copy\n* @returns {Uint8Array} new array\n*/\nfunction uint8array( arr ) {\n\treturn new Uint8Array( arr );\n}\n\n/**\n* Copies a `Uint8ClampedArray`.\n*\n* @private\n* @param {Uint8ClampedArray} arr - array to copy\n* @returns {Uint8ClampedArray} new array\n*/\nfunction uint8clampedarray( arr ) {\n\treturn new Uint8ClampedArray( arr );\n}\n\n/**\n* Copies an `Int16Array`.\n*\n* @private\n* @param {Int16Array} arr - array to copy\n* @returns {Int16Array} new array\n*/\nfunction int16array( arr ) {\n\treturn new Int16Array( arr );\n}\n\n/**\n* Copies a `Uint16Array`.\n*\n* @private\n* @param {Uint16Array} arr - array to copy\n* @returns {Uint16Array} new array\n*/\nfunction uint16array( arr ) {\n\treturn new Uint16Array( arr );\n}\n\n/**\n* Copies an `Int32Array`.\n*\n* @private\n* @param {Int32Array} arr - array to copy\n* @returns {Int32Array} new array\n*/\nfunction int32array( arr ) {\n\treturn new Int32Array( arr );\n}\n\n/**\n* Copies a `Uint32Array`.\n*\n* @private\n* @param {Uint32Array} arr - array to copy\n* @returns {Uint32Array} new array\n*/\nfunction uint32array( arr ) {\n\treturn new Uint32Array( arr );\n}\n\n/**\n* Copies a `Float32Array`.\n*\n* @private\n* @param {Float32Array} arr - array to copy\n* @returns {Float32Array} new array\n*/\nfunction float32array( arr ) {\n\treturn new Float32Array( arr );\n}\n\n/**\n* Copies a `Float64Array`.\n*\n* @private\n* @param {Float64Array} arr - array to copy\n* @returns {Float64Array} new array\n*/\nfunction float64array( arr ) {\n\treturn new Float64Array( arr );\n}\n\n/**\n* Returns a hash of functions for copying typed arrays.\n*\n* @private\n* @returns {Object} function hash\n*/\nfunction typedarrays() {\n\tvar out = {\n\t\t'int8array': int8array,\n\t\t'uint8array': uint8array,\n\t\t'uint8clampedarray': uint8clampedarray,\n\t\t'int16array': int16array,\n\t\t'uint16array': uint16array,\n\t\t'int32array': int32array,\n\t\t'uint32array': uint32array,\n\t\t'float32array': float32array,\n\t\t'float64array': float64array\n\t};\n\treturn out;\n}\n\n\n// MAIN //\n\nhash = typedarrays();\n\n\n// EXPORTS //\n\nmodule.exports = hash;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar regexp = require( '@stdlib/utils-regexp-from-string' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar propertyNames = require( '@stdlib/utils-property-names' );\nvar propertyDescriptor = require( '@stdlib/utils-property-descriptor' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar defineProperty = require( '@stdlib/utils-define-property' );\nvar copyBuffer = require( '@stdlib/buffer-from-buffer' );\nvar typedArrays = require( './typed_arrays.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Clones a class instance.\n*\n* ## Notes\n*\n* - This should **only** be used for simple cases. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This approach should be considered **fragile**.\n* - The function is greedy, disregarding the notion of a `level`. Instead, the function deep copies all properties, as we assume the concept of `level` applies only to the class instance reference but not to its internal state. This prevents, in theory, two instances from sharing state.\n*\n*\n* @private\n* @param {Object} val - class instance\n* @returns {Object} new instance\n*/\nfunction cloneInstance( val ) {\n\tvar cache;\n\tvar names;\n\tvar name;\n\tvar refs;\n\tvar desc;\n\tvar tmp;\n\tvar ref;\n\tvar i;\n\n\tcache = [];\n\trefs = [];\n\n\tref = Object.create( getPrototypeOf( val ) );\n\tcache.push( val );\n\trefs.push( ref );\n\n\tnames = propertyNames( val );\n\tfor ( i = 0; i < names.length; i++ ) {\n\t\tname = names[ i ];\n\t\tdesc = propertyDescriptor( val, name );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( val[name] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( val[name], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( ref, name, desc );\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( ref );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( ref );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( ref );\n\t}\n\treturn ref;\n}\n\n/**\n* Copies an error object.\n*\n* @private\n* @param {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error - error to copy\n* @returns {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error copy\n*\n* @example\n* var err1 = new TypeError( 'beep' );\n*\n* var err2 = copyError( err1 );\n* // returns \n*/\nfunction copyError( error ) {\n\tvar cache = [];\n\tvar refs = [];\n\tvar keys;\n\tvar desc;\n\tvar tmp;\n\tvar key;\n\tvar err;\n\tvar i;\n\n\t// Create a new error...\n\terr = new error.constructor( error.message );\n\n\tcache.push( error );\n\trefs.push( err );\n\n\t// If a `stack` property is present, copy it over...\n\tif ( error.stack ) {\n\t\terr.stack = error.stack;\n\t}\n\t// Node.js specific (system errors)...\n\tif ( error.code ) {\n\t\terr.code = error.code;\n\t}\n\tif ( error.errno ) {\n\t\terr.errno = error.errno;\n\t}\n\tif ( error.syscall ) {\n\t\terr.syscall = error.syscall;\n\t}\n\t// Any enumerable properties...\n\tkeys = objectKeys( error );\n\tfor ( i = 0; i < keys.length; i++ ) {\n\t\tkey = keys[ i ];\n\t\tdesc = propertyDescriptor( error, key );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( error[ key ] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( error[ key ], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( err, key, desc );\n\t}\n\treturn err;\n}\n\n\n// MAIN //\n\n/**\n* Recursively performs a deep copy of an input object.\n*\n* @private\n* @param {*} val - value to copy\n* @param {(Array|Object)} copy - copy\n* @param {Array} cache - an array of visited objects\n* @param {Array} refs - an array of object references\n* @param {NonNegativeInteger} level - copy depth\n* @returns {*} deep copy\n*/\nfunction deepCopy( val, copy, cache, refs, level ) {\n\tvar parent;\n\tvar keys;\n\tvar name;\n\tvar desc;\n\tvar ctor;\n\tvar key;\n\tvar ref;\n\tvar x;\n\tvar i;\n\tvar j;\n\n\tlevel -= 1;\n\n\t// Primitives and functions...\n\tif (\n\t\ttypeof val !== 'object' ||\n\t\tval === null\n\t) {\n\t\treturn val;\n\t}\n\tif ( isBuffer( val ) ) {\n\t\treturn copyBuffer( val );\n\t}\n\tif ( isError( val ) ) {\n\t\treturn copyError( val );\n\t}\n\t// Objects...\n\tname = typeOf( val );\n\n\tif ( name === 'date' ) {\n\t\treturn new Date( +val );\n\t}\n\tif ( name === 'regexp' ) {\n\t\treturn regexp( val.toString() );\n\t}\n\tif ( name === 'set' ) {\n\t\treturn new Set( val );\n\t}\n\tif ( name === 'map' ) {\n\t\treturn new Map( val );\n\t}\n\tif (\n\t\tname === 'string' ||\n\t\tname === 'boolean' ||\n\t\tname === 'number'\n\t) {\n\t\t// If provided an `Object`, return an equivalent primitive!\n\t\treturn val.valueOf();\n\t}\n\tctor = typedArrays[ name ];\n\tif ( ctor ) {\n\t\treturn ctor( val );\n\t}\n\t// Class instances...\n\tif (\n\t\tname !== 'array' &&\n\t\tname !== 'object'\n\t) {\n\t\t// Cloning requires ES5 or higher...\n\t\tif ( typeof Object.freeze === 'function' ) {\n\t\t\treturn cloneInstance( val );\n\t\t}\n\t\treturn {};\n\t}\n\t// Arrays and plain objects...\n\tkeys = objectKeys( val );\n\tif ( level > 0 ) {\n\t\tparent = name;\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tx = val[ key ];\n\n\t\t\t// Primitive, Buffer, special class instance...\n\t\t\tname = typeOf( x );\n\t\t\tif (\n\t\t\t\ttypeof x !== 'object' ||\n\t\t\t\tx === null ||\n\t\t\t\t(\n\t\t\t\t\tname !== 'array' &&\n\t\t\t\t\tname !== 'object'\n\t\t\t\t) ||\n\t\t\t\tisBuffer( x )\n\t\t\t) {\n\t\t\t\tif ( parent === 'object' ) {\n\t\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\t\tdesc.value = deepCopy( x );\n\t\t\t\t\t}\n\t\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t\t} else {\n\t\t\t\t\tcopy[ key ] = deepCopy( x );\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Circular reference...\n\t\t\ti = indexOf( cache, x );\n\t\t\tif ( i !== -1 ) {\n\t\t\t\tcopy[ key ] = refs[ i ];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Plain array or object...\n\t\t\tref = ( isArray( x ) ) ? new Array( x.length ) : {};\n\t\t\tcache.push( x );\n\t\t\trefs.push( ref );\n\t\t\tif ( parent === 'array' ) {\n\t\t\t\tcopy[ key ] = deepCopy( x, ref, cache, refs, level );\n\t\t\t} else {\n\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\tdesc.value = deepCopy( x, ref, cache, refs, level );\n\t\t\t\t}\n\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t}\n\t\t}\n\t} else if ( name === 'array' ) {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tcopy[ key ] = val[ key ];\n\t\t}\n\t} else {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\tdefineProperty( copy, key, desc );\n\t\t}\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( copy );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( copy );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( copy );\n\t}\n\treturn copy;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepCopy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar deepCopy = require( './deep_copy.js' );\n\n\n// MAIN //\n\n/**\n* Copies or deep clones a value to an arbitrary depth.\n*\n* @param {*} value - value to copy\n* @param {NonNegativeInteger} [level=+infinity] - copy depth\n* @throws {TypeError} `level` must be a nonnegative integer\n* @returns {*} value copy\n*\n* @example\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\nfunction copy( value, level ) {\n\tvar out;\n\tif ( arguments.length > 1 ) {\n\t\tif ( !isNonNegativeInteger( level ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `level` must be a nonnegative integer. Value: `' + level + '`.' );\n\t\t}\n\t\tif ( level === 0 ) {\n\t\t\treturn value;\n\t\t}\n\t} else {\n\t\tlevel = PINF;\n\t}\n\tout = ( isArray( value ) ) ? new Array( value.length ) : {};\n\treturn deepCopy( value, out, [value], [out], level );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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* Copy or deep clone a value to an arbitrary depth.\n*\n* @module @stdlib/utils-copy\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ {'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\n\n// MODULES //\n\nvar copy = require( './copy.js' );\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an object; e.g., `{}`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an object\n*\n* @example\n* var bool = isObject( {} );\n* // returns true\n*\n* @example\n* var bool = isObject( null );\n* // returns false\n*/\nfunction isObject( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t!isArray( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObject;\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\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar objectPrototype = Object.prototype;\n\n\n// FUNCTIONS //\n\n/**\n* Tests that an object only has own properties.\n*\n* @private\n* @param {Object} obj - value to test\n* @returns {boolean} boolean indicating if an object only has own properties\n*/\nfunction ownProps( obj ) {\n\tvar key;\n\n\t// NOTE: possibility of perf boost if key enumeration order is known (see http://stackoverflow.com/questions/18531624/isplainobject-thing).\n\tfor ( key in obj ) {\n\t\tif ( !hasOwnProp( obj, key ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n\n// MAIN //\n\n/**\n* Tests if a value is a plain object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a plain object\n*\n* @example\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* @example\n* var bool = isPlainObject( null );\n* // returns false\n*/\nfunction isPlainObject( value ) {\n\tvar proto;\n\n\t// Screen for obvious non-objects...\n\tif ( !isObject( value ) ) {\n\t\treturn false;\n\t}\n\t// Objects with no prototype (e.g., `Object.create( null )`) are plain...\n\tproto = getPrototypeOf( value );\n\tif ( !proto ) {\n\t\treturn true;\n\t}\n\t// Objects having a prototype are plain if and only if they are constructed with a global `Object` function and the prototype points to the prototype of a plain object...\n\treturn (\n\t\t// Cannot have own `constructor` property:\n\t\t!hasOwnProp( value, 'constructor' ) &&\n\n\t\t// Prototype `constructor` property must be a function (see also https://bugs.jquery.com/ticket/9897 and http://stackoverflow.com/questions/18531624/isplainobject-thing):\n\t\thasOwnProp( proto, 'constructor' ) &&\n\t\tisFunction( proto.constructor ) &&\n\t\tnativeClass( proto.constructor ) === '[object Function]' &&\n\n\t\t// Test for object-specific method:\n\t\thasOwnProp( proto, 'isPrototypeOf' ) &&\n\t\tisFunction( proto.isPrototypeOf ) &&\n\n\t\t(\n\t\t\t// Test if the prototype matches the global `Object` prototype (same realm):\n\t\t\tproto === objectPrototype ||\n\n\t\t\t// Test that all properties are own properties (cross-realm; *most* likely a plain object):\n\t\t\townProps( value )\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - options to validate\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {(Error|null)} error object or null\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );\n\t}\n\tif ( hasOwnProp( options, 'url' ) ) {\n\t\topts.url = options.url;\n\t\tif ( !isString( opts.url ) ) {\n\t\t\treturn new TypeError( 'invalid option. `url` option must be a string primitive. Option: `' + opts.url + '`.' );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'message' ) ) {\n\t\topts.message = options.message;\n\t\tif ( !isString( opts.message ) ) {\n\t\t\treturn new TypeError( 'invalid option. `message` option must be a string primitive. Option: `' + opts.message + '`.' );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\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* Test if a value is a plain object.\n*\n* @module @stdlib/assert-is-plain-object\n*\n* @example\n* var isPlainObject = require( '@stdlib/assert-is-plain-object' );\n*\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* bool = isPlainObject( null );\n* // returns false\n*/\n\n// MODULES //\n\nvar isPlainObject = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar replace = require( '@stdlib/string-replace' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Returns a function which formats an error message for production.\n*\n* @param {Options} options - function options\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {Function} error formatting function\n*\n* @example\n* var opts = {\n* 'url': 'https://stdlib.io/error-decoder.html'\n* };\n*\n* var fcn = factory( opts );\n* // returns \n*/\nfunction factory( options ) {\n\tvar opts;\n\tvar err;\n\topts = copy( defaults );\n\terr = validate( opts, options );\n\tif ( err ) {\n\t\tthrow err;\n\t}\n\treturn formatProdErrorMessage;\n\n\t/**\n\t* Formats an error message for production.\n\t*\n\t* @private\n\t* @param {string} code - error code\n\t* @param {*} ...args - error message arguments\n\t* @returns {string} formatted error message\n\t*/\n\tfunction formatProdErrorMessage() {\n\t\tvar code = arguments[ 0 ];\n\t\tvar url = opts.url + '?code='+code;\n\t\tvar msg;\n\t\tvar i;\n\t\tfor ( i = 1; i < arguments.length; i++ ) {\n\t\t\turl += '&arg[]=' + encodeURIComponent( arguments[ i ] );\n\t\t}\n\t\tmsg = replace( opts.message, '{{url}}', url );\n\t\tmsg = replace( msg, '{{code}}', code );\n\t\treturn msg;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Format an error message for production.\n*\n* @module @stdlib/error-tools-fmtprodmsg\n*\n* @example\n* var formatProdErrorMessage = require( '@stdlib/error-tools-fmtprodmsg' );\n*\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar formatProdErrorMessage = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( formatProdErrorMessage, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @name formatProdErrorMessage\n* @type {Function}\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\nvar formatProdErrorMessage = factory( defaults );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["defineProperty","Object","has_define_property_support","err","builtin","objectProtoype","prototype","toStr","toString","defineGetter","__defineGetter__","defineSetter","__defineSetter__","lookupGetter","__lookupGetter__","lookupSetter","__lookupSetter__","polyfill","obj","prop","descriptor","hasValue","hasGet","hasSet","call","TypeError","__proto__","value","Error","get","set","require$$1","require$$2","lib","require$$0","main","configurable","enumerable","writable","primitive","FLG","Symbol","hasSymbols","toStringTag","tostring","native_class","v","has","hasOwnProperty","property","toStrTag","hasOwnProp","isOwn","tag","out","valueOf","String","nativeClass","test","object","isPrimitive","isObject","setReadOnly","isString","require$$3","RE_CHARS","str","s","i","length","replace","substring","re","Boolean","isBoolean","codegen","Function","self_1","self","window_1","window","global","module","exports","getThis","Self","Win","Global","arguments","root","nodeList","document","childNodes","typedarray","Int8Array","RE","check_1","reFunctionName","Array","isArray","isObjectLike","predicate","len","arrayfun","_isBuffer","constructor","isBuffer","REGEXP","match","name","ctor","slice","exec","ctorName","typeOf","type","toLowerCase","RegExp","rescape","isFunction","isRegExp","search","newval","Number","isNumber","POSITIVE_INFINITY","NEGATIVE_INFINITY","floor","Math","x","PINF","NINF","isInt","integer","isInteger","isNonNegativeInteger","getProto","getPrototypeOf","proto","reRegExp","isNan","isnan","isCollection","index_of","arr","searchElement","fromIndex","keys","has_arguments_bug","has_builtin","bool","isArguments","bool$8","detect","detect_1","native","propertyIsEnumerable","bool$7","isEnum","hasStringEnumBug","isEnumerableProperty","require$$4","builtin_wrapper","has_enumerable_prototype_bug","has_non_enumerable_properties_bug","is_constructor_prototype","w","indexOf","isConstructorPrototype","EXCLUDED_KEYS","win","bool$4","k","check","hasAutomationEqualityBug","HAS_WINDOW","HAS_ENUM_PROTO_BUG","HAS_NON_ENUM_PROPS_BUG","error","NON_ENUMERABLE","wrapper","skipConstructor","skipPrototype","isFcn","p","push","getOwnPropertyNames","propertyNames","getOwnPropertyDescriptor","propertyDescriptor","desc","Buffer","from","buffer","hasInt8Array","isInt8Array","GlobalInt8Array","INT8_MAX","hasUint8Array","Uint8Array","isUint8Array","GlobalUint8Array","UINT8_MAX","hasUint8ClampedArray","Uint8ClampedArray","isUint8ClampedArray","GlobalUint8ClampedArray","hasInt16Array","Int16Array","isInt16Array","GlobalInt16Array","INT16_MAX","hasUint16Array","Uint16Array","isUint16Array","GlobalUint16Array","UINT16_MAX","hasInt32Array","Int32Array","isInt32Array","GlobalInt32Array","INT32_MAX","hasUint32Array","Uint32Array","isUint32Array","GlobalUint32Array","UINT32_MAX","hasFloat32Array","Float32Array","isFloat32Array","GlobalFloat32Array","hasFloat64Array","Float64Array","isFloat64Array","GlobalFloat64Array","NaN","require$$5","require$$6","require$$7","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","isError","regexp","objectKeys","require$$8","require$$9","require$$10","require$$11","copyBuffer","require$$12","typedArrays","deepCopy","val","copy","cache","refs","level","parent","key","ref","j","tmp","message","stack","code","errno","syscall","copyError","Date","Set","Map","freeze","names","create","isExtensible","preventExtensions","isSealed","seal","isFrozen","cloneInstance","copy_1","objectPrototype","isPrototypeOf","ownProps","validate","opts","options","url","defaults","factory_1","msg","encodeURIComponent","formatProdErrorMessage","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","RangeError","format"],"mappings":";6kBAsBA,ICAIA,EDA0C,mBAA1BC,OAAOD,eAAkCC,OAAOD,eAAiB,KC4BrF,IAAAE,EAbA,WAEC,IAEC,OADAF,EAAgB,GAAI,IAAK,KAClB,EACN,MAAQG,GACT,OAAO,ICiBTC,EALqBH,OAAOD,eC/BxBK,EAAiBJ,OAAOK,UACxBC,EAAQF,EAAeG,SACvBC,EAAeJ,EAAeK,iBAC9BC,EAAeN,EAAeO,iBAC9BC,EAAeR,EAAeS,iBAC9BC,EAAeV,EAAeW,iBAuFlC,IAAAC,EAnDA,SAAyBC,EAAKC,EAAMC,GACnC,IAAId,EACAe,EACAC,EACAC,EAEJ,GAAoB,iBAARL,GAA4B,OAARA,GAAsC,mBAAtBX,EAAMiB,KAAMN,GAC3D,MAAM,IAAIO,UAAW,+DAAiEP,EAAM,MAE7F,GAA2B,iBAAfE,GAA0C,OAAfA,GAAoD,mBAA7Bb,EAAMiB,KAAMJ,GACzE,MAAM,IAAIK,UAAW,oEAAsEL,EAAa,MAyBzG,IAvBAC,EAAa,UAAWD,KAGtBP,EAAaW,KAAMN,EAAKC,IACxBJ,EAAaS,KAAMN,EAAKC,IAGxBb,EAAYY,EAAIQ,UAChBR,EAAIQ,UAAYrB,SAGTa,EAAKC,GACZD,EAAKC,GAASC,EAAWO,MAGzBT,EAAIQ,UAAYpB,GAEhBY,EAAKC,GAASC,EAAWO,OAG3BL,EAAW,QAASF,EACpBG,EAAW,QAASH,EAEfC,IAAcC,GAAUC,GAC5B,MAAM,IAAIK,MAAO,wHASlB,OANKN,GAAUb,GACdA,EAAae,KAAMN,EAAKC,EAAMC,EAAWS,KAErCN,GAAUZ,GACdA,EAAaa,KAAMN,EAAKC,EAAMC,EAAWU,KAEnCZ,GCrEJd,EAAU2B,EACVd,EAAWe,EAefC,EAjB+BC,IASb9B,EAEAa,EC7BdjB,EAAiBkC,EAmCrB,IAAAC,EAZA,SAAmCjB,EAAKC,EAAMQ,GAC7C3B,EAAgBkB,EAAKC,EAAM,CAC1BiB,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,KCJXM,EAL+BC,ECA/B,IAAAK,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCMjB,ICdIa,EDIJ,WACC,MACmB,mBAAXC,QACoB,iBAApBA,OAAQ,OCPPC,GAqBV,ICTAT,EDEA,WACC,OAASO,GAAqC,iBAAvBC,OAAOE,aEf/BC,EALY3C,OAAOK,UAAUE,SCAzBD,EAAQ2B,EAiCZ,IAAAW,EAPA,SAAsBC,GACrB,OAAOvC,EAAMiB,KAAMsB,IC3BhBC,EAAM9C,OAAOK,UAAU0C,eAyC3B,ICjBAf,EDIA,SAAqBN,EAAOsB,GAC3B,OACCtB,SAKMoB,EAAIvB,KAAMG,EAAOsB,IEnCrBC,EAA+B,mBAAXT,OAA0BA,OAAOE,YAAc,GCAnEQ,EAAajB,EACbS,EDIaO,ECHb3C,EAAQyB,EAwDZ,ICpCI5B,EAAU2B,EACVd,EDKJ,SAAsB6B,GACrB,IAAIM,EACAC,EACAC,EAEJ,GAAKR,QACJ,OAAOvC,EAAMiB,KAAMsB,GAEpBO,EAAMP,EAAGH,GACTS,EAAQD,EAAYL,EAAGH,GAGvB,IACCG,EAAGH,QAAgB,EAClB,MAAQxC,GACT,OAAOI,EAAMiB,KAAMsB,GASpB,OAPAQ,EAAM/C,EAAMiB,KAAMsB,GAEbM,EACJN,EAAGH,GAAgBU,SAEZP,EAAGH,GAEJW,GCdRrB,EAjBqBC,IASNjB,EAEAb,EChCXmD,ECDUC,OAAOlD,UAAUiD,QDyB/B,IEvBIE,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADA4B,EAAQ/B,KAAMG,IACP,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB6B,SAGjBhB,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,EAAW9B,EA0Bf,ICSI+B,EAAc5B,EACd6B,EDjBJ,SAAmBpC,GAClB,OAASiC,EAAajC,IAAWkC,EAAUlC,ICkBxCkC,EAAWG,EAKfF,EAAaC,EAAU,cANL/B,GAOlB8B,EAAaC,EAAU,WAAYF,GAKnC,IAAA5B,EAAiB8B,EClDbA,EAAW7B,EAAsC0B,YAKjDK,EAAW,yBAqDf,ICzCAhC,EDIA,SAAkBiC,GACjB,IACIC,EACAC,EAEJ,IAAML,EAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAGrG,GAAkB,MAAbA,EAAK,GAGT,IAAME,EADAF,EAAIG,OACI,EAAGD,GAAK,GACH,MAAbF,EAAKE,GADcA,KAO1B,YAAW,IAANA,GAAgBA,GAAK,EAClBF,EAAII,QAASL,EAAU,SAM/BE,GAHAA,EAAID,EAAIK,UAAW,EAAGH,IAGhBE,QAASL,EAAU,QAGzBC,EAAMA,EAAK,GAAMC,EAAID,EAAIK,UAAWH,KE/CrCI,EALS,ICyBT,IAAAjC,EAPA,SAAoBZ,GACnB,MAA0B,kBAAVA,GCjBbnB,ECDWiE,QAAQnE,UAAUE,SDyBjC,IEvBIiD,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADAnB,EAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAoBhC,GACnB,MAAsB,iBAAVA,IACNA,aAAiB8C,UAGjBjC,EACGkB,EAAM/B,GAEoB,qBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,GAAW9B,EAkCf,ICAI+B,GAAc5B,EACdwC,GDRJ,SAAoB/C,GACnB,OAASiC,EAAajC,IAAWkC,GAAUlC,ICSxCkC,GAAWG,EAKfF,GAAaY,GAAW,cANN1C,GAOlB8B,GAAaY,GAAW,WAAYb,IAKpC,IAAA5B,GAAiByC,GCpCjB,IAAAC,GAPA,WACC,OAAO,IAAIC,SAAU,eAAd,ICFRC,GAL4B,iBAATC,KAAsBA,KAAO,KCKhDC,GAL8B,iBAAXC,OAAwBA,OAAS,6GCAhD9D,GAA0B,iBAAX+D,GAAwBA,GAAS,KAKpDC,OAAOC,QAAUjE,OCLbwD,GAAYxC,GAAuC0B,YACnDwB,GAAUrD,GACVsD,GAAOrD,GACPsD,GAAMtB,GACNuB,sCAkDJ,IAAApD,GA7BA,SAAoBwC,GACnB,GAAKa,UAAUnB,OAAS,CACvB,IAAMK,GAAWC,GAChB,MAAM,IAAIlD,UAAW,+DAA+DkD,EAAQ,MAE7F,GAAKA,EACJ,OAAOS,KAKT,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,MAAM,IAAI3D,MAAO,uDC3Cd6D,GCOYvD,KDNZwD,GAAWD,GAAKE,UAAYF,GAAKE,SAASC,WER1CC,GAAaC,UCEbC,GAAK7D,EACLwD,GHUaA,GGTbG,GDCaA,GC6BjB,IAAAG,GAnBA,WACC,MAEe,mBAAPD,IAGe,iBAAfF,IAGa,mBAAbH,ICST,IAAAvD,GAPA,WACC,MAAO,2BCEJ8D,GAAiBlE,GADHG,EAOL+D,GAAgB,SCjCR/D,MDsCrB,IAAAD,GAAiBgE,GEtCbxC,GAAcvB,EAwClB,ICpBAD,GDWKiE,MAAMC,QACND,MAAMC,QARX,SAAkBxE,GACjB,MAAkC,mBAAzB8B,GAAa9B,IEzBnBwE,GAAUjE,GC0Bd,ICGIkE,GDbJ,SAAuBzE,GACtB,OACW,OAAVA,GACiB,iBAAVA,GCQSO,EAOLkE,GAAc,oBFR3B,SAAmBC,GAClB,GAA0B,mBAAdA,EACX,MAAM,IAAI5E,UAAW,sDAAwD4E,EAAY,MAE1F,OASA,SAAgB1E,GACf,IAAI2E,EACAlC,EACJ,IAAM+B,GAASxE,GACd,OAAO,EAGR,GAAa,KADb2E,EAAM3E,EAAM0C,QAEX,OAAO,EAER,IAAMD,EAAI,EAAGA,EAAIkC,EAAKlC,IACrB,IAAiC,IAA5BiC,EAAW1E,EAAOyC,IACtB,OAAO,EAGT,OAAO,GEpBuCmC,CAAUH,KAK1D,IAAAnE,GAAiBmE,GCvCbA,GAAelE,GA+CnB,IC3BAD,GDOA,SAAmBN,GAClB,OACCyE,GAAczE,KAGbA,EAAM6E,WAEL7E,EAAM8E,aAGgC,mBAA/B9E,EAAM8E,YAAYC,UACzB/E,EAAM8E,YAAYC,SAAU/E,KEtC5B8B,GAAcvB,EACd6D,GAAKhE,GAA0C4E,OAC/CD,GAAW1E,GAuDf,IAAAG,GAxBA,SAA0BW,GACzB,IAAI8D,EACAC,EACAC,EAEJ,IAAe,YADfD,EAAOpD,GAAaX,GAAIiE,MAAO,GAAI,KACC,UAATF,IAAqB/D,EAAE2D,YAAc,CAE/D,GAA0B,iBAD1BK,EAAOhE,EAAE2D,aACQI,KAChB,OAAOC,EAAKD,KAGb,GADAD,EAAQb,GAAGiB,KAAMF,EAAKtG,YAErB,OAAOoG,EAAO,GAGhB,OAAKF,GAAU5D,GACP,SAED+D,GCnDJI,GCkBkB/E,GDmCtB,IErDI+E,GDkBkB/E,GCAtB,ICFIgF,GHkBJ,SAAiBpE,GAChB,IAAIqE,EAGJ,OAAW,OAANrE,EACG,OAKM,YAHdqE,SAAcrE,GAINmE,GAAUnE,GAAIsE,cAEfD,GG9BJlG,GDNJ,SAAiB6B,GAChB,OAAOmE,GAAUnE,GAAIsE,eCetBnF,GAZkBC,KAOajB,GAAWiG,GCtBtCA,GAAShF,GA2Bb,ICNAD,GDFA,SAAqBN,GAEpB,MAA6B,aAApBuF,GAAQvF,IErBdqF,GCFOK,OAAO/G,UAAU0G,KD0B5B,IEvBIvD,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADAqF,GAAKxF,KAAMG,IACJ,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBN,IA0CrB,IC1CIoF,GAAUpF,EACVqF,GAAaxF,GACbgC,GAAW/B,EAAsC4B,YACjD4D,GDuBJ,SAAmB7F,GAClB,MAAsB,iBAAVA,IACNA,aAAiB0F,SAGjB7E,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MC2BxB,ICvCAM,GDmBA,SAAkBiC,EAAKuD,EAAQC,GAC9B,IAAM3D,GAAUG,GACf,MAAM,IAAIzC,UAAW,wEAA0EyC,EAAM,MAEtG,GAAKH,GAAU0D,GACdA,EAASH,GAASG,GAClBA,EAAS,IAAIJ,OAAQI,EAAQ,UAEzB,IAAMD,GAAUC,GACpB,MAAM,IAAIhG,UAAW,+FAAiGgG,EAAS,MAEhI,IAAM1D,GAAU2D,KAAaH,GAAYG,GACxC,MAAM,IAAIjG,UAAW,gGAAkGiG,EAAS,MAEjI,OAAOxD,EAAII,QAASmD,EAAQC,IEhC7B,IAAAnF,GAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCAjBM,GCjBiB0F,OCAbnH,GCAS0B,GAMS5B,UAAUE,SDkBhC,IEvBIiD,GAAc1B,EACd4F,GAAS3F,GACT0B,GFSJ,SAAe/B,GACd,IAEC,OADAnB,GAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IETLqC,GARiBN,IA2CrB,IAAAyB,GAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiBgG,KAGjBnF,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MCnCpBiC,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd0F,GDfJ,SAAmBjG,GAClB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa8D,GAAU,cANL5F,IAOlB8B,GAAa8D,GAAU,WAAY/D,IAKnC,IAAA5B,GAAiB2F,GCvBjB3F,GALmB0F,OAAOE,kBCS1B5F,GA1BaC,GAqBa4F,kBChCtBC,GCsBQC,KAAKD,MDIjB,IENA9F,GFDA,SAAoBgG,GACnB,OAAQF,GAAME,KAAOA,GGpBlBC,GAAOhG,GACPiG,GAAOpG,GACPqG,GAAQpG,GAuBZ,IAAAqG,GAXA,SAAoB1G,GACnB,OACCA,EAAQuG,IACRvG,EAAQwG,IACRC,GAAOzG,IClBLiG,GAAW1F,GAAsC0B,YACjDwE,GAAQrG,GA6BZ,IAAAQ,GAVA,SAAoBZ,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,ICvBLiG,GAAW1F,GAAsC2B,SACjDuE,GAAQrG,GA6BZ,IAAA4B,GAVA,SAAoBhC,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICMI+B,GAAc5B,EACdoG,GDdJ,SAAoB3G,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICexCkC,GAAWG,GAKfF,GAAawE,GAAW,cANNtG,IAOlB8B,GAAawE,GAAW,WAAYzE,IAKpC,IAAA5B,GAAiBqG,GCvDbA,GAAYpG,GAAuC0B,YA6BvD,IAAArB,GAVA,SAA+BZ,GAC9B,OACC2G,GAAW3G,IACXA,GAAS,GCtBP2G,GAAYpG,GAAuC2B,SA6BvD,IAAAF,GAVA,SAA+BhC,GAC9B,OACC2G,GAAW3G,IACXA,EAAM4B,WAAa,GCtBjBK,GAAc1B,GACd2B,GAAW9B,GAsCf,ICGI+B,GAAc5B,EACdqG,GDXJ,SAA+B5G,GAC9B,OAASiC,GAAajC,IAAWkC,GAAUlC,ICYxCkC,GAAWG,GAKfF,GAAayE,GAAsB,cANjBvG,IAOlB8B,GAAayE,GAAsB,WAAY1E,IAK/C,IAAA5B,GAAiBsG,GCxDbC,GAAWvI,OAAOwI,eCatB,IAAAC,GARA,SAAmBxH,GAElB,OAAOA,EAAIQ,WCPR+B,GAAcvB,EACdsG,GAAWzG,GA+Bf,IAAAd,GAnBA,SAAyBC,GACxB,IAAIwH,EAAQF,GAAUtH,GACtB,OAAKwH,GAAmB,OAAVA,EACNA,EAEgC,sBAAnCjF,GAAavC,EAAIuF,aAEdvF,EAAIuF,YAAYnG,UAEnBY,aAAejB,OACZA,OAAOK,UAGR,MCzBJF,GHIaoI,GGHbvH,GAAWe,GCFXwG,GDAatG,GAQAjC,OAAOwI,gBACZrI,GAEAa,GCoBZ,ICdAgB,GDFA,SAAyBN,GACxB,OACCA,QAGO,MAGRA,EAAQ1B,OAAQ0B,GAET6G,GAAU7G,KEzBd8G,GAAiBvG,GACjBuB,GAAc1B,EAwClB,ICrBAE,GDAA,SAAkBN,GACjB,GAAsB,iBAAVA,GAAgC,OAAVA,EACjC,OAAO,EAGR,GAAKA,aAAiBC,MACrB,OAAO,EAGR,KAAQD,GAAQ,CACf,GAA8B,mBAAzB8B,GAAa9B,GACjB,OAAO,EAERA,EAAQ8G,GAAgB9G,GAEzB,OAAO,GEdR,IAAAQ,GAPA,WACC,MAAO,oCCWJwG,GAAW5G,GADGG,EAOLyG,GAAU,SChCRzG,UCAX6B,GAAW7B,EAAsC0B,YACjD+E,GFyCaA,GEXjB,ICdA1G,GDAA,SAAuBiC,GACtB,IAAMH,GAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAMrG,OAHAA,EAAMyE,KAAW3B,KAAM9C,IAGN,IAAImD,OAAQnD,EAAI,GAAIA,EAAI,IAAO,MEJjD,IAAA/B,GAPA,SAAgB8F,GACf,OAASA,GAAMA,GCfZL,GAAW1F,GAAsC0B,YACjDgF,GCcQ1G,GDmBZ,IAAAK,GAVA,SAAgBZ,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,IE3BLiG,GAAW1F,GAAsC2B,SACjD+E,GDcQ1G,GCeZ,IAAAyB,GAVA,SAAgBhC,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd2G,GDfJ,SAAgBlH,GACf,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa+E,GAAO,cANF7G,IAOlB8B,GAAa+E,GAAO,WAAYhF,IAKhC,IAAA5B,GAAiB4G,GCxDbP,GAAYpG,GAkChB,IClCI2G,GAAQ3G,GACR4G,GDmBJ,SAAuBnH,GACtB,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QENqB,kBDnBzBN,GAAW/B,EAAsC4B,YACjD0E,GAAYtE,GAAuCJ,YA0GvD,IAAAmF,GAhDA,SAAkBC,EAAKC,EAAeC,GACrC,IAAI5C,EACAlC,EACJ,IAAM0E,GAAcE,KAAUjF,GAAUiF,GACvC,MAAM,IAAIvH,UAAW,0EAA4EuH,EAAM,MAGxG,GAAa,KADb1C,EAAM0C,EAAI3E,QAET,OAAQ,EAET,GAA0B,IAArBmB,UAAUnB,OAAe,CAC7B,IAAMiE,GAAWY,GAChB,MAAM,IAAIzH,UAAW,6DAA+DyH,EAAY,MAEjG,GAAKA,GAAa,EAAI,CACrB,GAAKA,GAAa5C,EACjB,OAAQ,EAETlC,EAAI8E,OAEJ9E,EAAIkC,EAAM4C,GACD,IACR9E,EAAI,QAINA,EAAI,EAGL,GAAKyE,GAAOI,IACX,KAAQ7E,EAAIkC,EAAKlC,IAChB,GAAKyE,GAAOG,EAAI5E,IACf,OAAOA,OAIT,KAAQA,EAAIkC,EAAKlC,IAChB,GAAK4E,EAAK5E,KAAQ6E,EACjB,OAAO7E,EAIV,OAAQ,GErDTnC,GALcC,GClBd,IAAA9B,GAPA,SAAeuB,GACd,OAAO1B,OAAOkJ,KAAMlJ,OAAQ0B,KCrBzBwH,GAAOjH,GAmCX,IAAAkH,GAPA,WACC,OAlBD,WACC,OAA8C,KAArCD,GAAM3D,YAAe,IAAKnB,OAiB5BX,CAAM,EAAG,ICxBjB2F,QALoC,IAAhBpJ,OAAOkJ,KCAvB1F,GAAcvB,EA+BlB,IC1BIoH,GD0BJnH,GAPA,SAAsBR,GACrB,MAAkC,uBAAzB8B,GAAa9B,ICzBnB4H,GAAcrH,GA2BdsH,GAPJ,WACC,OAAOD,GAAa/D,WAMdiE,GAKP,IC3BIH,GD2BJI,GAAiBJ,GEDjBK,GAL2B1J,OAAOK,UAAUsJ,qBDHxCC,IAvBS3H,GAiBGV,KAAM,OAAQ,KAW9B,IE5BIuC,GAAW7B,EACX2G,GAAQ9G,GAAmC6B,YAC3C0E,GAAYtG,GAAuC4B,YACnDkG,GAAS9F,GACT+F,GFwBaT,GE6BjB,IAAAnH,GAzBA,SAA+BR,EAAOsB,GACrC,IAAIqG,EACJ,OACC3H,YAKD2H,EAAOQ,GAAOtI,KAAMG,EAAOsB,KACb8G,IAAoBhG,GAAUpC,IAIzCkH,GAFF5F,GAAYA,IAGXqF,GAAWrF,IACXA,GAAY,GACZA,EAAWtB,EAAM0C,OAGZiF,IC3BRrH,GAL2BC,GCnBvBiB,GAAajB,EACb8H,GAAuBjI,GACvBoE,GAAUnE,GACVsG,GAAYtE,GCiChB,IAAA/B,GAjBwBC,GACbH,GDQX,SAAsBJ,GACrB,OACW,OAAVA,GACiB,iBAAVA,IACNwE,GAASxE,IACc,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QAhCS4F,YAiCf9G,GAAYxB,EAAO,YAClBqI,GAAsBrI,EAAO,WEtC5B4H,GAAcrH,GACd9B,GAAU2B,GAKVgF,GAAQb,MAAM5F,UAAUyG,MA+B5B,IAAAmD,GAVA,SAAevI,GACd,OAAK4H,GAAa5H,GACVvB,GAAS2G,GAAMvF,KAAMG,IAEtBvB,GAASuB,ICnBjB,ICAAwI,GAZ2BjI,IDK3B,cCEuC,aCWvCkI,IAlB2BlI,GAKjB,CACT1B,SAAY,MAO0B,YCCvC,ICJI8I,GDIJe,GAPA,SAAiC1I,GAChC,OAASA,EAAM8E,aAAe9E,EAAM8E,YAAYnG,YAAcqB,GER3D2I,GAAwB,oBAAXtF,YAA2B,EAASA,ODAjD7B,GAAajB,EACbqI,GAAUxI,GACVmF,GAASlF,GACTwI,GAAyBxG,GACzByG,wPACAC,GCAaJ,GD2CbK,GAzBJ,WACC,IAAIC,EACJ,GAAuB,cAAlB1D,GAAQwD,IACZ,OAAO,EAER,IAAME,KAAKF,GACV,KAEmC,IAAjCH,GAASE,GAAeG,IACxBzH,GAAYuH,GAAKE,IACJ,OAAbF,GAAKE,IACkB,WAAvB1D,GAAQwD,GAAKE,KAEbJ,GAAwBE,GAAKE,IAE7B,MAAQzK,GACT,OAAO,EAGT,OAAO,EAMD0K,GAKP,IErDIvB,GAA2B,oBAAXtE,OCAhB8F,GHqDaxB,GGpDbkB,GAAyBzI,GACzBgJ,GDGazB,GCuBjB,IC5BIlD,GAAelE,GACfiB,GAAapB,EACbwH,GAAcvH,GACdgJ,GAAqBhH,GACrBiH,GAAyBhB,GACzBO,GDSJ,SAAkB7I,GACjB,IAAoB,IAAfoJ,KAAyBD,GAC7B,OAAON,GAAwB7I,GAEhC,IACC,OAAO6I,GAAwB7I,GAC9B,MAAQuJ,GACT,OAAO,ICfLC,iHAyEJ,IC7EI/K,GAAU4B,GACVoJ,GAAUpH,GACV/C,GDuBJ,SAAeU,GACd,IAAI0J,EACAC,EACAC,EACAjI,EACAsH,EACAY,EACApH,EAGJ,GADAd,EAAM,GACDiG,GAAa5H,GAAU,CAE3B,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,YAGb,OAAO8C,EAER,GAAsB,iBAAV3B,GAEX,GAAKA,EAAM0C,OAAS,IAAMlB,GAAYxB,EAAO,KAC5C,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,gBAGR,CAEN,IAAe,KADf+K,EAA2B,mBAAV5J,KACQyE,GAAczE,GACtC,OAAO2B,EAERgI,EAAkBN,IAAsBO,EAEzC,IAAMX,KAAKjJ,EACF2J,GAAuB,cAANV,IAAuBzH,GAAYxB,EAAOiJ,IAClEtH,EAAImI,KAAMjI,OAAQoH,IAGpB,GAAKK,GAEJ,IADAI,EAAkBb,GAAwB7I,GACpCyC,EAAI,EAAGA,EAAI+G,GAAe9G,OAAQD,IACvCoH,EAAIL,GAAgB/G,GACZiH,GAAyB,gBAANG,IAAyBrI,GAAYxB,EAAO6J,IACtElI,EAAImI,KAAMjI,OAAQgI,IAIrB,OAAOlI,GEnDRrB,GDrBkBF,GADIG,KA6BbkJ,GAEAhL,GAGDa,GE7BRoI,QALmD,IAA/BpJ,OAAOyL,oBCAvBC,GAAgB1L,OAAOyL,oBAgC3B,IChCIvC,GAAOjH,GCgCX,IAAAD,GAjBkBC,GFUlB,SAA8BP,GAC7B,OAAOgK,GAAe1L,OAAQ0B,KCA/B,SAA8BA,GAC7B,OAAOwH,GAAMlJ,OAAQ0B,KEtBtB0H,QALwD,IAApCpJ,OAAO2L,yBCAvBC,GAAqB5L,OAAO2L,yBAuChC,ICvCIzI,GAAajB,ECkCjB,IAAAD,GAjBkBC,GFUlB,SAAmCP,EAAOsB,GACzC,IAAI6I,EACJ,OAAKnK,cAIa,KADlBmK,EAAOD,GAAoBlK,EAAOsB,IAF1B,KAG4B6I,GCLrC,SAAmCnK,EAAOsB,GACzC,OAAKE,GAAYxB,EAAOsB,GAChB,CACNb,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,EAAOsB,IAGX,iyqBEvBR,ICDId,uJCb2B4J,ODc3B9K,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GAjB2BC,KASnBC,GAEAlB,GEjBJqI,GANapH,GACJH,GAKiBiK,MCN1BtF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAI,GAVA,SAAqB8J,GACpB,IAAMvF,GAAUuF,GACf,MAAM,IAAIxK,UAAW,oDAAsDwK,EAAS,KAErF,OAAOF,GAAOC,KAAMC,IC1BjBvF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAd,GAVA,SAAqBgL,GACpB,IAAMvF,GAAUuF,GACf,MAAM,IAAIxK,UAAW,oDAAsDwK,EAAS,KAErF,OAAO,IAAIF,GAAQE,ICOpBhK,GHtBiBqH,GGMNvH,GACIC,GClBXyB,GAAcvB,EAKdgK,GAAsC,mBAAdpG,UA6B5B,IClCI3D,GAA8B,mBAAd2D,UAA6BA,UAAY,KCAzDqG,GFwBJ,SAAsBxK,GACrB,OACGuK,IAAgBvK,aAAiBmE,WACV,uBAAzBrC,GAAa9B,IExBXyK,GDEajK,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAgC,mBAApBoD,GACX,OAAO,EAGR,IACCpD,EAAM,IAAIoD,GAAiB,CAAE,EAAG,MAAO,KAAMC,MAC7C/C,EACC6C,GAAanD,IACA,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEO,MDDZA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb8B,mBAAd0F,UAA6BA,eAAY,EDczD7E,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB0BC,KFSlB9B,GAEAa,GGvBJwC,GAAcvB,EAKdoK,GAAwC,mBAAfC,WA6B7B,IClCIpK,GAA+B,mBAAfoK,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuB7K,GACtB,OACG2K,IAAiB3K,aAAiB4K,YACX,wBAAzB9I,GAAa9B,IEzBX8K,GDGatK,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArByD,GACX,OAAO,EAGR,IAECzD,EAAM,IAAIyD,GADVzD,EAAM,CAAE,EAAG,MAAO,KAAM0D,IAAaA,MAErCpD,EACCkD,GAAcxD,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ0D,MAAb1D,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCb+B,mBAAfmM,WAA8BA,gBAAa,EDc3DtL,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdyK,GAAsD,mBAAtBC,kBA6BpC,IClCIzK,GAAsC,mBAAtByK,kBAAqCA,kBAAoB,KCAzEC,GFwBJ,SAA8BlL,GAC7B,OACGgL,IAAwBhL,aAAiBiL,mBAClB,+BAAzBnJ,GAAa9B,IE1BXmL,GDIa3K,GCuCjB,IAAAA,GA7BA,WACC,IAAImH,EACAN,EAEJ,GAAwC,mBAA5B8D,GACX,OAAO,EAGR,IACC9D,EAAM,IAAI8D,GAAyB,EAAG,EAAG,EAAG,EAAG,KAAM,KAAM,IAAK,MAChExD,EACCuD,GAAqB7D,IACR,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,MAAbA,EAAK,IACQ,MAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbsC,mBAAtBwM,kBAAqCA,uBAAoB,EDczE3L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjBkCC,KFS1B9B,GAEAa,GGvBJwC,GAAcvB,EAKd6K,GAAwC,mBAAfC,WA6B7B,IClCI7K,GAA+B,mBAAf6K,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBtL,GACtB,OACGoL,IAAiBpL,aAAiBqL,YACX,wBAAzBvJ,GAAa9B,IExBXuL,GDEa/K,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArBkE,GACX,OAAO,EAGR,IACClE,EAAM,IAAIkE,GAAkB,CAAE,EAAG,MAAO,KAAMC,QAC9C7D,EACC2D,GAAcjE,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,QDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAf4M,WAA8BA,gBAAa,EDc3D/L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdkL,GAA0C,mBAAhBC,YA6B9B,IClCIlL,GAAgC,mBAAhBkL,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwB3L,GACvB,OACGyL,IAAkBzL,aAAiB0L,aACZ,yBAAzB5J,GAAa9B,IEzBX4L,GDGapL,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBuE,GACX,OAAO,EAGR,IAECvE,EAAM,IAAIuE,GADVvE,EAAM,CAAE,EAAG,MAAO,KAAMwE,MAAcA,QAEtClE,EACCgE,GAAetE,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQwE,QAAbxE,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhBiN,YAA+BA,iBAAc,EDc7DpM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKduL,GAAwC,mBAAfC,WA6B7B,IClCIvL,GAA+B,mBAAfuL,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBhM,GACtB,OACG8L,IAAiB9L,aAAiB+L,YACX,wBAAzBjK,GAAa9B,IExBXiM,GDEazL,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB4E,GACX,OAAO,EAGR,IACC5E,EAAM,IAAI4E,GAAkB,CAAE,EAAG,MAAO,KAAMC,aAC9CvE,EACCqE,GAAc3E,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,aDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAfsN,WAA8BA,gBAAa,EDc3DzM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd4L,GAA0C,mBAAhBC,YA6B9B,IClCI5L,GAAgC,mBAAhB4L,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwBrM,GACvB,OACGmM,IAAkBnM,aAAiBoM,aACZ,yBAAzBtK,GAAa9B,IEzBXsM,GDGa9L,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBiF,GACX,OAAO,EAGR,IAECjF,EAAM,IAAIiF,GADVjF,EAAM,CAAE,EAAG,MAAO,KAAMkF,WAAcA,aAEtC5E,EACC0E,GAAehF,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQkF,aAAblF,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhB2N,YAA+BA,iBAAc,EDc7D9M,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdiM,GAA4C,mBAAjBC,aA6B/B,IClCIjM,GAAiC,mBAAjBiM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB1M,GACxB,OACGwM,IAAmBxM,aAAiByM,cACb,0BAAzB3K,GAAa9B,IE1BXuG,GAAOnG,GACPuM,GDGanM,GCqCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvBsF,GACX,OAAO,EAGR,IACCtF,EAAM,IAAIsF,GAAoB,CAAE,EAAK,MAAO,KAAM,OAClDhF,EACC+E,GAAgBrF,IACH,IAAbA,EAAK,IACQ,oBAAbA,EAAK,KACS,oBAAdA,EAAK,IACLA,EAAK,KAAQd,GAEb,MAAQ/H,GACTmJ,GAAO,EAER,OAAOA,GCtBR,ICDIlJ,GCbiC,mBAAjBgO,aAAgCA,kBAAe,EDc/DnN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB6BC,KFSrB9B,GAEAa,GGvBJwC,GAAcvB,EAKdqM,GAA4C,mBAAjBC,aA6B/B,IClCIrM,GAAiC,mBAAjBqM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB9M,GACxB,OACG4M,IAAmB5M,aAAiB6M,cACb,0BAAzB/K,GAAa9B,IE1BX+M,GDIavM,GCoCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvB0F,GACX,OAAO,EAGR,IACC1F,EAAM,IAAI0F,GAAoB,CAAE,EAAK,MAAO,KAAMC,MAClDrF,EACCmF,GAAgBzF,IACH,IAAbA,EAAK,IACQ,OAAbA,EAAK,KACS,OAAdA,EAAK,IACLA,EAAK,IAAQA,EAAK,GAElB,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCrBR,ICKIxC,GANA1G,GCbiC,mBAAjBoO,aAAgCA,kBAAe,EDc/DvN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCajBkF,GET4B5E,KFSrB9B,GAEAa,GAMR,IG7BI6E,GAAY5D,GACZqK,GAAaxK,GACb6K,GAAoB5K,GACpBgL,GAAahJ,GACbqJ,GAAcpD,GACdyD,GAAakB,GACbb,GAAcc,GACdT,GAAeU,GACfN,GHqBa1H,GGJjB,SAASiI,GAAW/F,GACnB,OAAO,IAAIlD,GAAWkD,GAUvB,SAASgG,GAAYhG,GACpB,OAAO,IAAIuD,GAAYvD,GAUxB,SAASiG,GAAmBjG,GAC3B,OAAO,IAAI4D,GAAmB5D,GAU/B,SAASkG,GAAYlG,GACpB,OAAO,IAAIgE,GAAYhE,GAUxB,SAASmG,GAAanG,GACrB,OAAO,IAAIqE,GAAarE,GAUzB,SAASoG,GAAYpG,GACpB,OAAO,IAAI0E,GAAY1E,GAUxB,SAASqG,GAAarG,GACrB,OAAO,IAAI+E,GAAa/E,GAUzB,SAASsG,GAActG,GACtB,OAAO,IAAIoF,GAAcpF,GAU1B,SAASuG,GAAcvG,GACtB,OAAO,IAAIwF,GAAcxF,GAgC1B,IClJI7F,GAAajB,EACbiE,GAAUpE,GACV2E,GAAW1E,GACXwN,GAAUxL,GACVkD,GAAS+C,GACTwF,GAASb,GACTrE,GAAUsE,GACVa,GAAaZ,GACbnD,GAAgBgE,GAChB9D,GAAqB+D,GACrBnH,GAAiBoH,GACjB7P,GAAiB8P,EACjBC,GAAaC,GACbC,GD+GO,CACTlB,UAAaA,GACbC,WAAcA,GACdC,kBAAqBA,GACrBC,WAAcA,GACdC,YAAeA,GACfC,WAAcA,GACdC,YAAeA,GACfC,aAAgBA,GAChBC,aAAgBA,ICQlB,SAASW,GAAUC,EAAKC,EAAMC,EAAOC,EAAMC,GAC1C,IAAIC,EACArH,EACAtC,EACAiF,EACAhF,EACA2J,EACAC,EACAzI,EACA7D,EACAuM,EAKJ,GAHAJ,GAAS,EAIO,iBAARJ,GACC,OAARA,EAEA,OAAOA,EAER,GAAKzJ,GAAUyJ,GACd,OAAOJ,GAAYI,GAEpB,GAAKX,GAASW,GACb,OAnFF,SAAoBjF,GACnB,IAEI/B,EACA2C,EACA8E,EACAH,EACAtQ,EACAiE,EAPAiM,EAAQ,GACRC,EAAO,GA8BX,IArBAnQ,EAAM,IAAI+K,EAAMzE,YAAayE,EAAM2F,SAEnCR,EAAM5E,KAAMP,GACZoF,EAAK7E,KAAMtL,GAGN+K,EAAM4F,QACV3Q,EAAI2Q,MAAQ5F,EAAM4F,OAGd5F,EAAM6F,OACV5Q,EAAI4Q,KAAO7F,EAAM6F,MAEb7F,EAAM8F,QACV7Q,EAAI6Q,MAAQ9F,EAAM8F,OAEd9F,EAAM+F,UACV9Q,EAAI8Q,QAAU/F,EAAM+F,SAGrB9H,EAAOuG,GAAYxE,GACb9G,EAAI,EAAGA,EAAI+E,EAAK9E,OAAQD,IAC7BqM,EAAMtH,EAAM/E,GACZ0H,EAAOD,GAAoBX,EAAOuF,GAC7BtN,GAAY2I,EAAM,WACtB8E,EAAQzK,GAAS+E,EAAOuF,IAAY,GAAK,GACzC3E,EAAKnK,MAAQuO,GAAUhF,EAAOuF,GAAOG,EAAKP,EAAOC,GAAO,IAEzDtQ,GAAgBG,EAAKsQ,EAAK3E,GAE3B,OAAO3L,EA0CC+Q,CAAWf,GAKnB,GAAc,UAFdtJ,EAAOK,GAAQiJ,IAGd,OAAO,IAAIgB,MAAOhB,GAEnB,GAAc,WAATtJ,EACJ,OAAO4I,GAAQU,EAAI3P,YAEpB,GAAc,QAATqG,EACJ,OAAO,IAAIuK,IAAKjB,GAEjB,GAAc,QAATtJ,EACJ,OAAO,IAAIwK,IAAKlB,GAEjB,GACU,WAATtJ,GACS,YAATA,GACS,WAATA,EAGA,OAAOsJ,EAAI5M,UAGZ,GADAuD,EAAOmJ,GAAapJ,GAEnB,OAAOC,EAAMqJ,GAGd,GACU,UAATtJ,GACS,WAATA,EAGA,MAA8B,mBAAlB5G,OAAOqR,OA1KrB,SAAwBnB,GACvB,IAAIE,EACAkB,EACA1K,EACAyJ,EACAxE,EACA8E,EACAF,EACAtM,EAUJ,IARAiM,EAAQ,GACRC,EAAO,GAEPI,EAAMzQ,OAAOuR,OAAQ/I,GAAgB0H,IACrCE,EAAM5E,KAAM0E,GACZG,EAAK7E,KAAMiF,GAEXa,EAAQ5F,GAAewE,GACjB/L,EAAI,EAAGA,EAAImN,EAAMlN,OAAQD,IAC9ByC,EAAO0K,EAAOnN,GACd0H,EAAOD,GAAoBsE,EAAKtJ,GAC3B1D,GAAY2I,EAAM,WACtB8E,EAAQzK,GAASgK,EAAItJ,IAAY,GAAK,GACtCiF,EAAKnK,MAAQuO,GAAUC,EAAItJ,GAAO+J,EAAKP,EAAOC,GAAO,IAEtDtQ,GAAgB0Q,EAAK7J,EAAMiF,GAW5B,OATM7L,OAAOwR,aAActB,IAC1BlQ,OAAOyR,kBAAmBhB,GAEtBzQ,OAAO0R,SAAUxB,IACrBlQ,OAAO2R,KAAMlB,GAETzQ,OAAO4R,SAAU1B,IACrBlQ,OAAOqR,OAAQZ,GAETA,EAuIEoB,CAAe3B,GAEhB,GAIR,GADAhH,EAAOuG,GAAYS,GACdI,EAAQ,EAEZ,IADAC,EAAS3J,EACH8J,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAE7B1I,EAAIkI,EADJM,EAAMtH,EAAMwH,IAIZ9J,EAAOK,GAAQe,GAED,iBAANA,GACD,OAANA,GAEU,UAATpB,GACS,WAATA,GAEDH,GAAUuB,GAEM,WAAXuI,GACJ1E,EAAOD,GAAoBsE,EAAKM,GAC3BtN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQuO,GAAUjI,IAExBjI,GAAgBoQ,EAAMK,EAAK3E,IAE3BsE,EAAMK,GAAQP,GAAUjI,IAMd,KADZ7D,EAAImG,GAAS8F,EAAOpI,KAMpByI,EAAQvK,GAAS8B,GAAQ,IAAI/B,MAAO+B,EAAE5D,QAAW,GACjDgM,EAAM5E,KAAMxD,GACZqI,EAAK7E,KAAMiF,GACK,UAAXF,EACJJ,EAAMK,GAAQP,GAAUjI,EAAGyI,EAAKL,EAAOC,EAAMC,IAE7CzE,EAAOD,GAAoBsE,EAAKM,GAC3BtN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQuO,GAAUjI,EAAGyI,EAAKL,EAAOC,EAAMC,IAE7CvQ,GAAgBoQ,EAAMK,EAAK3E,KAd3BsE,EAAMK,GAAQH,EAAMlM,QAiBhB,GAAc,UAATyC,EACX,IAAM8J,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAE7BP,EADAK,EAAMtH,EAAMwH,IACER,EAAKM,QAGpB,IAAME,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAC7BF,EAAMtH,EAAMwH,GACZ7E,EAAOD,GAAoBsE,EAAKM,GAChCzQ,GAAgBoQ,EAAMK,EAAK3E,GAY7B,OATM7L,OAAOwR,aAActB,IAC1BlQ,OAAOyR,kBAAmBtB,GAEtBnQ,OAAO0R,SAAUxB,IACrBlQ,OAAO2R,KAAMxB,GAETnQ,OAAO4R,SAAU1B,IACrBlQ,OAAOqR,OAAQlB,GAETA,EAMR,IC3RIjK,GAAUjE,GACVqG,GAAuBxG,GAAmD6B,YAC1EsE,GAAOlG,GACPkO,GDwRaA,GCtOjB,IAAA6B,GAnBA,SAAepQ,EAAO4O,GACrB,IAAIjN,EACJ,GAAKkC,UAAUnB,OAAS,EAAI,CAC3B,IAAMkE,GAAsBgI,GAC3B,MAAM,IAAI9O,UAAW,oEAAsE8O,EAAQ,MAEpG,GAAe,IAAVA,EACJ,OAAO5O,OAGR4O,EAAQrI,GAGT,OADA5E,EAAQ6C,GAASxE,GAAY,IAAIuE,MAAOvE,EAAM0C,QAAW,GAClD6L,GAAUvO,EAAO2B,EAAK,CAAC3B,GAAQ,CAAC2B,GAAMiN,ICd9CtO,GALWC,GC5BPiE,GAAUjE,GA8Bd,IC9BI2B,GDmBJ,SAAmBlC,GAClB,MACkB,iBAAVA,GACG,OAAVA,IACCwE,GAASxE,ICtBR4F,GAAaxF,GACb0G,GAAiBzG,GACjBmB,GAAaa,EACbP,GAAcwG,EAKd+H,GAAkB/R,OAAOK,UAgF7B,IAAA6B,GAvCA,SAAwBR,GACvB,IAAI+G,EAGJ,QAAM7E,GAAUlC,OAIhB+G,EAAQD,GAAgB9G,MAOtBwB,GAAYxB,EAAO,gBAGpBwB,GAAYuF,EAAO,gBACnBnB,GAAYmB,EAAMjC,cACmB,sBAArChD,GAAaiF,EAAMjC,cAGnBtD,GAAYuF,EAAO,kBACnBnB,GAAYmB,EAAMuJ,iBAIjBvJ,IAAUsJ,IAzDb,SAAmB9Q,GAClB,IAAIuP,EAGJ,IAAMA,KAAOvP,EACZ,IAAMiC,GAAYjC,EAAKuP,GACtB,OAAO,EAGT,OAAO,EAmDLyB,CAAUvQ,MCjFTkC,GCegB3B,GDdhBiB,GAAapB,EACbgC,GAAW/B,EAAsC4B,YAqCrD,wJEvCIU,GAAUpC,GACVkO,GAAOrO,GACPoQ,GFeJ,SAAmBC,EAAMC,GACxB,OAAMxO,GAAUwO,GAGXlP,GAAYkP,EAAS,SACzBD,EAAKE,IAAMD,EAAQC,KACbvO,GAAUqO,EAAKE,MACb,IAAI7Q,UAAW,qEAAuE2Q,EAAKE,IAAM,MAGrGnP,GAAYkP,EAAS,aACzBD,EAAKvB,QAAUwB,EAAQxB,SACjB9M,GAAUqO,EAAKvB,UACb,IAAIpP,UAAW,yEAA2E2Q,EAAKvB,QAAU,MAG3G,KAdC,IAAIpP,UAAW,iEAAmE4Q,EAAU,OEhBjGE,GAAWvO,GAwDf,IAAAwO,GAnCA,SAAkBH,GACjB,IAAID,EACAjS,EAGJ,GAFAiS,EAAOhC,GAAMmC,IACbpS,EAAMgS,GAAUC,EAAMC,GAErB,MAAMlS,EAEP,OAUA,WACC,IAEIsS,EACArO,EAHA2M,EAAOvL,UAAW,GAClB8M,EAAMF,EAAKE,IAAM,SAASvB,EAG9B,IAAM3M,EAAI,EAAGA,EAAIoB,UAAUnB,OAAQD,IAClCkO,GAAO,UAAYI,mBAAoBlN,UAAWpB,IAInD,OAFAqO,EAAMnO,GAAS8N,EAAKvB,QAAS,UAAWyB,GACxCG,EAAMnO,GAASmO,EAAK,WAAY1B,KCtC9B4B,GCbUzQ,GACCH,IDWGG,EAOLyQ,GAAwB,UALvB3Q,IAUd,IAAAC,GAAiB0Q,UEiFjB,WACC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjP,EACAwM,EACAvM,EASJ,IANAwO,EAAUpN,UAAW,GACrBqN,EAASrN,UAAW,GAGpBsN,GADAG,EAAQzN,UAAW,GADnBwN,GAHAD,EAAQvN,UAAW,IAGLnB,UAECA,OACf8O,EAAMN,EACAzO,EAAI,EAAGA,EAAI4O,EAAO5O,IAAM,CAI7B,GAHAgP,EAAIL,EAAO3O,GACXuM,EAAInL,UAAWpB,EAAE,GAEH,WADd8O,EAAOD,EAAO7O,EAAE0O,IAEVnC,EAAI,EACRA,EAAI,EACOA,GAAKyC,IAChBzC,EAAIyC,EAAI,QAEH,GAAc,SAATF,EACNvC,EAAI,GACRA,GAAKyC,GACI,GAEG,KADXzC,GAAKyC,KAEJzC,GAAKyC,GAGIzC,GAAKyC,IAChBzC,GAAKyC,IACKA,IACTzC,GAAKyC,QAGD,GAAKzC,EAAI,GAAKA,GAAKyC,EACzB,MAAM,IAAIC,WAAYC,GAAQ,+FAAgGlP,EAAGuM,KAElIxM,EAAIyO,EAASxO,IAGJ,GAAgB,IAAXyO,EACbM,GAAOxC,EAAIxM,EAEXgP,GAAOxC,EAAIxM,EAGb,OAAOgP"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 25f81ac..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..4d9b415 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).sub2ind=r()}(this,(function(){"use strict";function t(t){var r=t.default;if("function"==typeof r){var e=function(){return r.apply(this,arguments)};e.prototype=r.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(t).forEach((function(r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})})),e}var r="function"==typeof Object.defineProperty?Object.defineProperty:null;var e=function(){try{return r({},"x",{}),!0}catch(t){return!1}},n=Object.defineProperty,o=Object.prototype,i=o.toString,u=o.__defineGetter__,a=o.__defineSetter__,f=o.__lookupGetter__,c=o.__lookupSetter__;var s=function(t,r,e){var n,s,l,h;if("object"!=typeof t||null===t||"[object Array]"===i.call(t))throw new TypeError("invalid argument. First argument must be an object. Value: `"+t+"`.");if("object"!=typeof e||null===e||"[object Array]"===i.call(e))throw new TypeError("invalid argument. Property descriptor must be an object. Value: `"+e+"`.");if((s="value"in e)&&(f.call(t,r)||c.call(t,r)?(n=t.__proto__,t.__proto__=o,delete t[r],t[r]=e.value,t.__proto__=n):t[r]=e.value),l="get"in e,h="set"in e,s&&(l||h))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return l&&u&&u.call(t,r,e.get),h&&a&&a.call(t,r,e.set),t},l=n,h=s,p=e()?l:h,y=p;var v=function(t,r,e){y(t,r,{configurable:!1,enumerable:!1,writable:!1,value:e})},g=v;var w=function(t){return"string"==typeof t};var d=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var b=function(){return d&&"symbol"==typeof Symbol.toStringTag},m=Object.prototype.toString,A=m;var E=function(t){return A.call(t)},_=Object.prototype.hasOwnProperty;var O=function(t,r){return null!=t&&_.call(t,r)},P="function"==typeof Symbol?Symbol.toStringTag:"",j=O,R=P,T=m;var U=E,S=function(t){var r,e,n;if(null==t)return T.call(t);e=t[R],r=j(t,R);try{t[R]=void 0}catch(r){return T.call(t)}return n=T.call(t),r?t[R]=e:delete t[R],n},I=b()?S:U,B=String.prototype.valueOf;var Y=I,x=function(t){try{return B.call(t),!0}catch(t){return!1}},C=b();var M=function(t){return"object"==typeof t&&(t instanceof String||(C?x(t):"[object String]"===Y(t)))},L=w,F=M;var D=g,N=function(t){return L(t)||F(t)},k=M;D(N,"isPrimitive",w),D(N,"isObject",k);var V=N,z=V.isPrimitive,G=/[-\/\\^$*+?.()|[\]{}]/g;var X=function(t){var r,e;if(!z(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");if("/"===t[0])for(e=t.length-1;e>=0&&"/"!==t[e];e--);return void 0===e||e<=0?t.replace(G,"\\$&"):(r=(r=t.substring(1,e)).replace(G,"\\$&"),t=t[0]+r+t.substring(e))},$=/./;var H=function(t){return"boolean"==typeof t},W=Boolean.prototype.toString;var q=I,J=function(t){try{return W.call(t),!0}catch(t){return!1}},Z=b();var K=function(t){return"object"==typeof t&&(t instanceof Boolean||(Z?J(t):"[object Boolean]"===q(t)))},Q=H,tt=K;var rt=g,et=function(t){return Q(t)||tt(t)},nt=K;rt(et,"isPrimitive",H),rt(et,"isObject",nt);var ot=et;var it=function(){return new Function("return this;")()},ut="object"==typeof self?self:null,at="object"==typeof window?window:null,ft="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},ct="object"==typeof ft?ft:null;module.exports=ct;var st=ot.isPrimitive,lt=it,ht=ut,pt=at,yt=t(Object.freeze({__proto__:null}));var vt=function(t){if(arguments.length){if(!st(t))throw new TypeError("invalid argument. Must provide a boolean primitive. Value: `"+t+"`.");if(t)return lt()}if(ht)return ht;if(pt)return pt;if(yt)return yt;throw new Error("unexpected error. Unable to resolve global object.")},gt=vt(),wt=gt.document&>.document.childNodes,dt=Int8Array,bt=$,mt=wt,At=dt;var Et=function(){return"function"==typeof bt||"object"==typeof At||"function"==typeof mt};var _t=function(){return/^\s*function\s*([^(]*)/i},Ot=_t;g(Ot,"REGEXP",_t());var Pt=Ot,jt=I;var Rt=Array.isArray?Array.isArray:function(t){return"[object Array]"===jt(t)},Tt=Rt;var Ut=function(t){return null!==t&&"object"==typeof t};g(Ut,"isObjectLikeArray",function(t){if("function"!=typeof t)throw new TypeError("invalid argument. Must provide a function. Value: `"+t+"`.");return function(r){var e,n;if(!Tt(r))return!1;if(0===(e=r.length))return!1;for(n=0;ndr&&br(t)},Ar=hr.isPrimitive,Er=mr;var _r=function(t){return Ar(t)&&Er(t)},Or=hr.isObject,Pr=mr;var jr=function(t){return Or(t)&&Pr(t.valueOf())},Rr=_r,Tr=jr;var Ur=g,Sr=function(t){return Rr(t)||Tr(t)},Ir=jr;Ur(Sr,"isPrimitive",_r),Ur(Sr,"isObject",Ir);var Br=Sr,Yr=Br.isPrimitive;var xr=function(t){return Yr(t)&&t>=0},Cr=Br.isObject;var Mr=function(t){return Cr(t)&&t.valueOf()>=0},Lr=xr,Fr=Mr;var Dr=g,Nr=function(t){return Lr(t)||Fr(t)},kr=Mr;Dr(Nr,"isPrimitive",xr),Dr(Nr,"isObject",kr);var Vr=Nr,zr=Object.getPrototypeOf;var Gr=function(t){return t.__proto__},Xr=I,$r=Gr;var Hr=function(t){var r=$r(t);return r||null===r?r:"[object Function]"===Xr(t.constructor)?t.constructor.prototype:t instanceof Object?Object.prototype:null},Wr=zr,qr=Hr,Jr=zt(Object.getPrototypeOf)?Wr:qr;var Zr=function(t){return null==t?null:(t=Object(t),Jr(t))},Kr=Zr,Qr=I;var te=function(t){if("object"!=typeof t||null===t)return!1;if(t instanceof Error)return!0;for(;t;){if("[object Error]"===Qr(t))return!0;t=Kr(t)}return!1};var re=function(){return/^\/((?:\\\/|[^\/])+)\/([imgy]*)$/},ee=re;g(ee,"REGEXP",re());var ne=V.isPrimitive,oe=ee;var ie=function(t){if(!ne(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");return(t=oe().exec(t))?new RegExp(t[1],t[2]):null};var ue=function(t){return t!=t},ae=hr.isPrimitive,fe=ue;var ce=function(t){return ae(t)&&fe(t)},se=hr.isObject,le=ue;var he=function(t){return se(t)&&le(t.valueOf())},pe=ce,ye=he;var ve=g,ge=function(t){return pe(t)||ye(t)},we=he;ve(ge,"isPrimitive",ce),ve(ge,"isObject",we);var de=ge,be=gr;var me=de,Ae=function(t){return"object"==typeof t&&null!==t&&"number"==typeof t.length&&be(t.length)&&t.length>=0&&t.length<=9007199254740991},Ee=V.isPrimitive,_e=Br.isPrimitive;var Oe=function(t,r,e){var n,o;if(!Ae(t)&&!Ee(t))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+t+"`.");if(0===(n=t.length))return-1;if(3===arguments.length){if(!_e(e))throw new TypeError("invalid argument. `fromIndex` must be an integer. Value: `"+e+"`.");if(e>=0){if(e>=n)return-1;o=e}else(o=n+e)<0&&(o=0)}else o=0;if(me(r)){for(;o=0&&r=0&&t.length<=4294967295&&Ge(t,"callee")&&!Xe(t,"callee")},qe=We,Je=je,Ze=Array.prototype.slice;var Ke=function(t){return qe(t)?Je(Ze.call(t)):Je(t)};var Qe=ze((function(){}),"prototype"),tn=!ze({toString:null},"toString");var rn,en=function(t){return t.constructor&&t.constructor.prototype===t},nn="undefined"==typeof window?void 0:window,on=O,un=Pe,an=kt,fn=en,cn=["console","external","frame","frameElement","frames","innerHeight","innerWidth","outerHeight","outerWidth","pageXOffset","pageYOffset","parent","scrollLeft","scrollTop","scrollX","scrollY","self","webkitIndexedDB","webkitStorageInfo","window"],sn=nn;rn=function(){var t;if("undefined"===an(sn))return!1;for(t in sn)try{-1===un(cn,t)&&on(sn,t)&&null!==sn[t]&&"object"===an(sn[t])&&fn(sn[t])}catch(t){return!0}return!1}();var ln="undefined"!=typeof window,hn=rn,pn=en,yn=ln;var vn=St,gn=O,wn=We,dn=Qe,bn=tn,mn=function(t){if(!1===yn&&!hn)return pn(t);try{return pn(t)}catch(t){return!1}},An=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"];var En=je,_n=Ke,On=function(t){var r,e,n,o,i,u,a;if(o=[],wn(t)){for(a=0;a0&&!gn(t,"0"))for(a=0;a>18&63]+xn[o>>12&63]+xn[o>>6&63]+xn[63&o]);return i.join("")}function Nn(t){var r;Ln||Fn();for(var e=t.length,n=e%3,o="",i=[],u=16383,a=0,f=e-n;af?f:a+u));return 1===n?(r=t[e-1],o+=xn[r>>2],o+=xn[r<<4&63],o+="=="):2===n&&(r=(t[e-2]<<8)+t[e-1],o+=xn[r>>10],o+=xn[r>>4&63],o+=xn[r<<2&63],o+="="),i.push(o),i.join("")}function kn(t,r,e,n,o){var i,u,a=8*o-n-1,f=(1<>1,s=-7,l=e?o-1:0,h=e?-1:1,p=t[r+l];for(l+=h,i=p&(1<<-s)-1,p>>=-s,s+=a;s>0;i=256*i+t[r+l],l+=h,s-=8);for(u=i&(1<<-s)-1,i>>=-s,s+=n;s>0;u=256*u+t[r+l],l+=h,s-=8);if(0===i)i=1-c;else{if(i===f)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),i-=c}return(p?-1:1)*u*Math.pow(2,i-n)}function Vn(t,r,e,n,o,i){var u,a,f,c=8*i-o-1,s=(1<>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,y=n?1:-1,v=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,u=s):(u=Math.floor(Math.log(r)/Math.LN2),r*(f=Math.pow(2,-u))<1&&(u--,f*=2),(r+=u+l>=1?h/f:h*Math.pow(2,1-l))*f>=2&&(u++,f/=2),u+l>=s?(a=0,u=s):u+l>=1?(a=(r*f-1)*Math.pow(2,o),u+=l):(a=r*Math.pow(2,l-1)*Math.pow(2,o),u=0));o>=8;t[e+p]=255&a,p+=y,a/=256,o-=8);for(u=u<0;t[e+p]=255&u,p+=y,u/=256,c-=8);t[e+p-y]|=128*v}var zn={}.toString,Gn=Array.isArray||function(t){return"[object Array]"==zn.call(t)};Wn.TYPED_ARRAY_SUPPORT=void 0===ft.TYPED_ARRAY_SUPPORT||ft.TYPED_ARRAY_SUPPORT;var Xn=$n();function $n(){return Wn.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Hn(t,r){if($n()=$n())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+$n().toString(16)+" bytes");return 0|t}function to(t){return!(null==t||!t._isBuffer)}function ro(t,r){if(to(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return Uo(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return So(t).length;default:if(n)return Uo(t).length;r=(""+r).toLowerCase(),n=!0}}function eo(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return wo(this,r,e);case"utf8":case"utf-8":return po(this,r,e);case"ascii":return vo(this,r,e);case"latin1":case"binary":return go(this,r,e);case"base64":return ho(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return bo(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function no(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function oo(t,r,e,n,o){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0){if(!o)return-1;e=0}if("string"==typeof r&&(r=Wn.from(r,n)),to(r))return 0===r.length?-1:io(t,r,e,n,o);if("number"==typeof r)return r&=255,Wn.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):io(t,[r],e,n,o);throw new TypeError("val must be string, number or Buffer")}function io(t,r,e,n,o){var i,u=1,a=t.length,f=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,a/=2,f/=2,e/=2}function c(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(o){var s=-1;for(i=e;ia&&(e=a-f),i=e;i>=0;i--){for(var l=!0,h=0;ho&&(n=o):n=o;var i=r.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var u=0;u>8,o=e%256,i.push(o),i.push(n);return i}(r,t.length-e),t,e,n)}function ho(t,r,e){return 0===r&&e===t.length?Nn(t):Nn(t.slice(r,e))}function po(t,r,e){e=Math.min(t.length,e);for(var n=[],o=r;o239?4:c>223?3:c>191?2:1;if(o+l<=e)switch(l){case 1:c<128&&(s=c);break;case 2:128==(192&(i=t[o+1]))&&(f=(31&c)<<6|63&i)>127&&(s=f);break;case 3:i=t[o+1],u=t[o+2],128==(192&i)&&128==(192&u)&&(f=(15&c)<<12|(63&i)<<6|63&u)>2047&&(f<55296||f>57343)&&(s=f);break;case 4:i=t[o+1],u=t[o+2],a=t[o+3],128==(192&i)&&128==(192&u)&&128==(192&a)&&(f=(15&c)<<18|(63&i)<<12|(63&u)<<6|63&a)>65535&&f<1114112&&(s=f)}null===s?(s=65533,l=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=l}return function(t){var r=t.length;if(r<=yo)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),""},Wn.prototype.compare=function(t,r,e,n,o){if(!to(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),r<0||e>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&r>=e)return 0;if(n>=o)return-1;if(r>=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),a=Math.min(i,u),f=this.slice(n,o),c=t.slice(r,e),s=0;so)&&(e=o),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return uo(this,t,r,e);case"utf8":case"utf-8":return ao(this,t,r,e);case"ascii":return fo(this,t,r,e);case"latin1":case"binary":return co(this,t,r,e);case"base64":return so(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return lo(this,t,r,e);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},Wn.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var yo=4096;function vo(t,r,e){var n="";e=Math.min(t.length,e);for(var o=r;on)&&(e=n);for(var o="",i=r;ie)throw new RangeError("Trying to access beyond buffer length")}function Ao(t,r,e,n,o,i){if(!to(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>o||rt.length)throw new RangeError("Index out of range")}function Eo(t,r,e,n){r<0&&(r=65535+r+1);for(var o=0,i=Math.min(t.length-e,2);o>>8*(n?o:1-o)}function _o(t,r,e,n){r<0&&(r=4294967295+r+1);for(var o=0,i=Math.min(t.length-e,4);o>>8*(n?o:3-o)&255}function Oo(t,r,e,n,o,i){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function Po(t,r,e,n,o){return o||Oo(t,0,e,4),Vn(t,r,e,n,23,4),e+4}function jo(t,r,e,n,o){return o||Oo(t,0,e,8),Vn(t,r,e,n,52,8),e+8}Wn.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(o*=256);)n+=this[t+--r]*o;return n},Wn.prototype.readUInt8=function(t,r){return r||mo(t,1,this.length),this[t]},Wn.prototype.readUInt16LE=function(t,r){return r||mo(t,2,this.length),this[t]|this[t+1]<<8},Wn.prototype.readUInt16BE=function(t,r){return r||mo(t,2,this.length),this[t]<<8|this[t+1]},Wn.prototype.readUInt32LE=function(t,r){return r||mo(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Wn.prototype.readUInt32BE=function(t,r){return r||mo(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Wn.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||mo(t,r,this.length);for(var n=this[t],o=1,i=0;++i=(o*=128)&&(n-=Math.pow(2,8*r)),n},Wn.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||mo(t,r,this.length);for(var n=r,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*r)),i},Wn.prototype.readInt8=function(t,r){return r||mo(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Wn.prototype.readInt16LE=function(t,r){r||mo(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},Wn.prototype.readInt16BE=function(t,r){r||mo(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},Wn.prototype.readInt32LE=function(t,r){return r||mo(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Wn.prototype.readInt32BE=function(t,r){return r||mo(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Wn.prototype.readFloatLE=function(t,r){return r||mo(t,4,this.length),kn(this,t,!0,23,4)},Wn.prototype.readFloatBE=function(t,r){return r||mo(t,4,this.length),kn(this,t,!1,23,4)},Wn.prototype.readDoubleLE=function(t,r){return r||mo(t,8,this.length),kn(this,t,!0,52,8)},Wn.prototype.readDoubleBE=function(t,r){return r||mo(t,8,this.length),kn(this,t,!1,52,8)},Wn.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||Ao(this,t,r,e,Math.pow(2,8*e)-1,0);var o=1,i=0;for(this[r]=255&t;++i=0&&(i*=256);)this[r+o]=t/i&255;return r+e},Wn.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,1,255,0),Wn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},Wn.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,65535,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):Eo(this,t,r,!0),r+2},Wn.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,65535,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):Eo(this,t,r,!1),r+2},Wn.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,4294967295,0),Wn.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):_o(this,t,r,!0),r+4},Wn.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,4294967295,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):_o(this,t,r,!1),r+4},Wn.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Ao(this,t,r,e,o-1,-o)}var i=0,u=1,a=0;for(this[r]=255&t;++i>0)-a&255;return r+e},Wn.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Ao(this,t,r,e,o-1,-o)}var i=e-1,u=1,a=0;for(this[r+i]=255&t;--i>=0&&(u*=256);)t<0&&0===a&&0!==this[r+i+1]&&(a=1),this[r+i]=(t/u>>0)-a&255;return r+e},Wn.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,1,127,-128),Wn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},Wn.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,32767,-32768),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):Eo(this,t,r,!0),r+2},Wn.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,32767,-32768),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):Eo(this,t,r,!1),r+2},Wn.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,2147483647,-2147483648),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):_o(this,t,r,!0),r+4},Wn.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):_o(this,t,r,!1),r+4},Wn.prototype.writeFloatLE=function(t,r,e){return Po(this,t,r,!0,e)},Wn.prototype.writeFloatBE=function(t,r,e){return Po(this,t,r,!1,e)},Wn.prototype.writeDoubleLE=function(t,r,e){return jo(this,t,r,!0,e)},Wn.prototype.writeDoubleBE=function(t,r,e){return jo(this,t,r,!1,e)},Wn.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--o)t[o+r]=this[o+e];else if(i<1e3||!Wn.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(i=r;i55295&&e<57344){if(!o){if(e>56319){(r-=3)>-1&&i.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&i.push(239,191,189);continue}o=e;continue}if(e<56320){(r-=3)>-1&&i.push(239,191,189),o=e;continue}e=65536+(o-55296<<10|e-56320)}else o&&(r-=3)>-1&&i.push(239,191,189);if(o=null,e<128){if((r-=1)<0)break;i.push(e)}else if(e<2048){if((r-=2)<0)break;i.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;i.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;i.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return i}function So(t){return function(t){var r,e,n,o,i,u;Ln||Fn();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[a-2]?2:"="===t[a-1]?1:0,u=new Mn(3*a/4-i),n=i>0?a-4:a;var f=0;for(r=0,e=0;r>16&255,u[f++]=o>>8&255,u[f++]=255&o;return 2===i?(o=Cn[t.charCodeAt(r)]<<2|Cn[t.charCodeAt(r+1)]>>4,u[f++]=255&o):1===i&&(o=Cn[t.charCodeAt(r)]<<10|Cn[t.charCodeAt(r+1)]<<4|Cn[t.charCodeAt(r+2)]>>2,u[f++]=o>>8&255,u[f++]=255&o),u}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Ro,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Io(t,r,e,n){for(var o=0;o=r.length||o>=t.length);++o)r[o+e]=t[o];return o}function Bo(t){return null!=t&&(!!t._isBuffer||Yo(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&Yo(t.slice(0,0))}(t))}function Yo(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var xo=Object.freeze({__proto__:null,Buffer:Wn,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),Wn.alloc(+t)},isBuffer:Bo,kMaxLength:Xn}),Co=Wn;module.exports=Co;var Mo=Bt,Lo=t(Object.freeze({__proto__:null}));var Fo=function(){var t,r;if("function"!=typeof Lo)return!1;try{r="function"==typeof Lo.from?Lo.from([1,2,3,4]):new Lo([1,2,3,4]),t=Mo(r)&&1===r[0]&&2===r[1]&&3===r[2]&&4===r[3]}catch(r){t=!1}return t},Do=Fo;var No=t(xo).Buffer,ko=function(){throw new Error("not implemented")},Vo=Do()?No:ko,zo=zt(Vo.from),Go=Bt,Xo=Vo;var $o=function(t){if(!Go(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return Xo.from(t)},Ho=Bt,Wo=Vo;var qo=function(t){if(!Ho(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return new Wo(t)},Jo=zo?$o:qo,Zo=I,Ko="function"==typeof Int8Array;var Qo="function"==typeof Int8Array?Int8Array:null,ti=function(t){return Ko&&t instanceof Int8Array||"[object Int8Array]"===Zo(t)},ri=Qo;var ei=function(){var t,r;if("function"!=typeof ri)return!1;try{r=new ri([1,3.14,-3.14,128]),t=ti(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-128===r[3]}catch(r){t=!1}return t};var ni="function"==typeof Int8Array?Int8Array:void 0,oi=function(){throw new Error("not implemented")},ii=ei()?ni:oi,ui=I,ai="function"==typeof Uint8Array;var fi="function"==typeof Uint8Array?Uint8Array:null,ci=function(t){return ai&&t instanceof Uint8Array||"[object Uint8Array]"===ui(t)},si=fi;var li=function(){var t,r;if("function"!=typeof si)return!1;try{r=new si(r=[1,3.14,-3.14,256,257]),t=ci(r)&&1===r[0]&&3===r[1]&&253===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var hi="function"==typeof Uint8Array?Uint8Array:void 0,pi=function(){throw new Error("not implemented")},yi=li()?hi:pi,vi=I,gi="function"==typeof Uint8ClampedArray;var wi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:null,di=function(t){return gi&&t instanceof Uint8ClampedArray||"[object Uint8ClampedArray]"===vi(t)},bi=wi;var mi=function(){var t,r;if("function"!=typeof bi)return!1;try{r=new bi([-1,0,1,3.14,4.99,255,256]),t=di(r)&&0===r[0]&&0===r[1]&&1===r[2]&&3===r[3]&&5===r[4]&&255===r[5]&&255===r[6]}catch(r){t=!1}return t};var Ai="function"==typeof Uint8ClampedArray?Uint8ClampedArray:void 0,Ei=function(){throw new Error("not implemented")},_i=mi()?Ai:Ei,Oi=I,Pi="function"==typeof Int16Array;var ji="function"==typeof Int16Array?Int16Array:null,Ri=function(t){return Pi&&t instanceof Int16Array||"[object Int16Array]"===Oi(t)},Ti=ji;var Ui=function(){var t,r;if("function"!=typeof Ti)return!1;try{r=new Ti([1,3.14,-3.14,32768]),t=Ri(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-32768===r[3]}catch(r){t=!1}return t};var Si="function"==typeof Int16Array?Int16Array:void 0,Ii=function(){throw new Error("not implemented")},Bi=Ui()?Si:Ii,Yi=I,xi="function"==typeof Uint16Array;var Ci="function"==typeof Uint16Array?Uint16Array:null,Mi=function(t){return xi&&t instanceof Uint16Array||"[object Uint16Array]"===Yi(t)},Li=Ci;var Fi=function(){var t,r;if("function"!=typeof Li)return!1;try{r=new Li(r=[1,3.14,-3.14,65536,65537]),t=Mi(r)&&1===r[0]&&3===r[1]&&65533===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var Di="function"==typeof Uint16Array?Uint16Array:void 0,Ni=function(){throw new Error("not implemented")},ki=Fi()?Di:Ni,Vi=I,zi="function"==typeof Int32Array;var Gi="function"==typeof Int32Array?Int32Array:null,Xi=function(t){return zi&&t instanceof Int32Array||"[object Int32Array]"===Vi(t)},$i=Gi;var Hi=function(){var t,r;if("function"!=typeof $i)return!1;try{r=new $i([1,3.14,-3.14,2147483648]),t=Xi(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-2147483648===r[3]}catch(r){t=!1}return t};var Wi="function"==typeof Int32Array?Int32Array:void 0,qi=function(){throw new Error("not implemented")},Ji=Hi()?Wi:qi,Zi=I,Ki="function"==typeof Uint32Array;var Qi="function"==typeof Uint32Array?Uint32Array:null,tu=function(t){return Ki&&t instanceof Uint32Array||"[object Uint32Array]"===Zi(t)},ru=Qi;var eu=function(){var t,r;if("function"!=typeof ru)return!1;try{r=new ru(r=[1,3.14,-3.14,4294967296,4294967297]),t=tu(r)&&1===r[0]&&3===r[1]&&4294967293===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var nu="function"==typeof Uint32Array?Uint32Array:void 0,ou=function(){throw new Error("not implemented")},iu=eu()?nu:ou,uu=I,au="function"==typeof Float32Array;var fu="function"==typeof Float32Array?Float32Array:null,cu=function(t){return au&&t instanceof Float32Array||"[object Float32Array]"===uu(t)},su=pr,lu=fu;var hu=function(){var t,r;if("function"!=typeof lu)return!1;try{r=new lu([1,3.14,-3.14,5e40]),t=cu(r)&&1===r[0]&&3.140000104904175===r[1]&&-3.140000104904175===r[2]&&r[3]===su}catch(r){t=!1}return t};var pu="function"==typeof Float32Array?Float32Array:void 0,yu=function(){throw new Error("not implemented")},vu=hu()?pu:yu,gu=I,wu="function"==typeof Float64Array;var du="function"==typeof Float64Array?Float64Array:null,bu=function(t){return wu&&t instanceof Float64Array||"[object Float64Array]"===gu(t)},mu=du;var Au=function(){var t,r;if("function"!=typeof mu)return!1;try{r=new mu([1,3.14,-3.14,NaN]),t=bu(r)&&1===r[0]&&3.14===r[1]&&-3.14===r[2]&&r[3]!=r[3]}catch(r){t=!1}return t};var Eu,_u="function"==typeof Float64Array?Float64Array:void 0,Ou=function(){throw new Error("not implemented")};Eu=Au()?_u:Ou;var Pu=ii,ju=yi,Ru=_i,Tu=Bi,Uu=ki,Su=Ji,Iu=iu,Bu=vu,Yu=Eu;function xu(t){return new Pu(t)}function Cu(t){return new ju(t)}function Mu(t){return new Ru(t)}function Lu(t){return new Tu(t)}function Fu(t){return new Uu(t)}function Du(t){return new Su(t)}function Nu(t){return new Iu(t)}function ku(t){return new Bu(t)}function Vu(t){return new Yu(t)}var zu=O,Gu=Rt,Xu=Bt,$u=te,Hu=kt,Wu=ie,qu=Pe,Ju=Pn,Zu=Un,Ku=Yn,Qu=Zr,ta=p,ra=Jo,ea={int8array:xu,uint8array:Cu,uint8clampedarray:Mu,int16array:Lu,uint16array:Fu,int32array:Du,uint32array:Nu,float32array:ku,float64array:Vu};function na(t,r,e,n,o){var i,u,a,f,c,s,l,h,p,y;if(o-=1,"object"!=typeof t||null===t)return t;if(Xu(t))return ra(t);if($u(t))return function(t){var r,e,n,o,i,u,a=[],f=[];for(i=new t.constructor(t.message),a.push(t),f.push(i),t.stack&&(i.stack=t.stack),t.code&&(i.code=t.code),t.errno&&(i.errno=t.errno),t.syscall&&(i.syscall=t.syscall),r=Ju(t),u=0;u0)for(i=a,y=0;y1){if(!ia(r))throw new TypeError("invalid argument. `level` must be a nonnegative integer. Value: `"+r+"`.");if(0===r)return t}else r=ua;return e=oa(t)?new Array(t.length):{},aa(t,e,[t],[e],r)},ca=fa,sa=Rt;var la=function(t){return"object"==typeof t&&null!==t&&!sa(t)},ha=zt,pa=Zr,ya=O,va=I,ga=Object.prototype;var wa=function(t){var r;return!!la(t)&&(!(r=pa(t))||!ya(t,"constructor")&&ya(r,"constructor")&&ha(r.constructor)&&"[object Function]"===va(r.constructor)&&ya(r,"isPrototypeOf")&&ha(r.isPrototypeOf)&&(r===ga||function(t){var r;for(r in t)if(!ya(t,r))return!1;return!0}(t)))},da=wa,ba=O,ma=V.isPrimitive;var Aa={url:"https://stdlib.io/docs/api/latest/error-decoder.html",message:"Minified stdlib error code: {{code}}. Visit {{url}} for the full message."},Ea=Kt,_a=ca,Oa=function(t,r){return da(r)?ba(r,"url")&&(t.url=r.url,!ma(t.url))?new TypeError("invalid option. `url` option must be a string primitive. Option: `"+t.url+"`."):ba(r,"message")&&(t.message=r.message,!ma(t.message))?new TypeError("invalid option. `message` option must be a string primitive. Option: `"+t.message+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.")},Pa=Aa;var ja=function(t){var r,e;if(r=_a(Pa),e=Oa(r,t))throw e;return function(){var t,e,n=arguments[0],o=r.url+"?code="+n;for(e=1;e=f&&(s=f-1);else if("wrap"===u)s<0?(s+=f)<0&&0!==(s%=f)&&(s+=f):s>=f&&(s-=f)>=f&&(s%=f);else if(s<0||s>=f)throw new RangeError(Ta("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",l,s));(c=t[l])<0&&0===r?a-=s*c:a+=s*c}return a}})); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..e1abfe1 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/utils-define-property/lib/define_property.js","../node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js","../node_modules/@stdlib/utils-define-property/lib/builtin.js","../node_modules/@stdlib/utils-define-property/lib/polyfill.js","../node_modules/@stdlib/utils-define-property/lib/index.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/primitive.js","../node_modules/@stdlib/assert-has-symbol-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostring.js","../node_modules/@stdlib/utils-native-class/lib/native_class.js","../node_modules/@stdlib/assert-has-own-property/lib/main.js","../node_modules/@stdlib/assert-has-own-property/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostringtag.js","../node_modules/@stdlib/utils-native-class/lib/polyfill.js","../node_modules/@stdlib/utils-native-class/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/try2valueof.js","../node_modules/@stdlib/assert-is-string/lib/valueof.js","../node_modules/@stdlib/assert-is-string/lib/object.js","../node_modules/@stdlib/assert-is-string/lib/main.js","../node_modules/@stdlib/assert-is-string/lib/index.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/main.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/re.js","../node_modules/@stdlib/assert-is-boolean/lib/primitive.js","../node_modules/@stdlib/assert-is-boolean/lib/try2serialize.js","../node_modules/@stdlib/assert-is-boolean/lib/tostring.js","../node_modules/@stdlib/assert-is-boolean/lib/object.js","../node_modules/@stdlib/assert-is-boolean/lib/main.js","../node_modules/@stdlib/assert-is-boolean/lib/index.js","../node_modules/@stdlib/utils-global/lib/codegen.js","../node_modules/@stdlib/utils-global/lib/self.js","../node_modules/@stdlib/utils-global/lib/window.js","../node_modules/@stdlib/utils-global/lib/global.js","../node_modules/@stdlib/utils-global/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/nodelist.js","../node_modules/@stdlib/utils-global/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/typedarray.js","../node_modules/@stdlib/utils-type-of/lib/check.js","../node_modules/@stdlib/regexp-function-name/lib/main.js","../node_modules/@stdlib/regexp-function-name/lib/index.js","../node_modules/@stdlib/regexp-function-name/lib/regexp.js","../node_modules/@stdlib/assert-is-array/lib/main.js","../node_modules/@stdlib/assert-is-array/lib/index.js","../node_modules/@stdlib/assert-tools-array-function/lib/arrayfcn.js","../node_modules/@stdlib/assert-is-object-like/lib/main.js","../node_modules/@stdlib/assert-is-object-like/lib/index.js","../node_modules/@stdlib/assert-is-buffer/lib/main.js","../node_modules/@stdlib/assert-is-buffer/lib/index.js","../node_modules/@stdlib/utils-constructor-name/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/typeof.js","../node_modules/@stdlib/utils-constructor-name/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/polyfill.js","../node_modules/@stdlib/utils-type-of/lib/index.js","../node_modules/@stdlib/assert-is-function/lib/main.js","../node_modules/@stdlib/assert-is-function/lib/index.js","../node_modules/@stdlib/assert-is-regexp/lib/try2exec.js","../node_modules/@stdlib/assert-is-regexp/lib/exec.js","../node_modules/@stdlib/assert-is-regexp/lib/main.js","../node_modules/@stdlib/string-replace/lib/replace.js","../node_modules/@stdlib/string-replace/lib/index.js","../node_modules/@stdlib/assert-is-number/lib/primitive.js","../node_modules/@stdlib/number-ctor/lib/index.js","../node_modules/@stdlib/number-ctor/lib/number.js","../node_modules/@stdlib/assert-is-number/lib/try2serialize.js","../node_modules/@stdlib/assert-is-number/lib/tostring.js","../node_modules/@stdlib/assert-is-number/lib/object.js","../node_modules/@stdlib/assert-is-number/lib/main.js","../node_modules/@stdlib/assert-is-number/lib/index.js","../node_modules/@stdlib/constants-float64-pinf/lib/index.js","../node_modules/@stdlib/constants-float64-ninf/lib/index.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/is_integer.js","../node_modules/@stdlib/math-base-special-floor/lib/main.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-integer/lib/integer.js","../node_modules/@stdlib/assert-is-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-integer/lib/object.js","../node_modules/@stdlib/assert-is-integer/lib/main.js","../node_modules/@stdlib/assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/object.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/main.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/index.js","../node_modules/@stdlib/utils-get-prototype-of/lib/native.js","../node_modules/@stdlib/utils-get-prototype-of/lib/proto.js","../node_modules/@stdlib/utils-get-prototype-of/lib/polyfill.js","../node_modules/@stdlib/utils-get-prototype-of/lib/detect.js","../node_modules/@stdlib/utils-get-prototype-of/lib/get_prototype_of.js","../node_modules/@stdlib/utils-get-prototype-of/lib/index.js","../node_modules/@stdlib/assert-is-error/lib/main.js","../node_modules/@stdlib/assert-is-error/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/main.js","../node_modules/@stdlib/regexp-regexp/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/regexp.js","../node_modules/@stdlib/utils-regexp-from-string/lib/from_string.js","../node_modules/@stdlib/utils-regexp-from-string/lib/index.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/primitive.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-nan/lib/object.js","../node_modules/@stdlib/assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-collection/lib/main.js","../node_modules/@stdlib/utils-index-of/lib/index_of.js","../node_modules/@stdlib/constants-array-max-typed-array-length/lib/index.js","../node_modules/@stdlib/utils-index-of/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin.js","../node_modules/@stdlib/utils-keys/lib/has_arguments_bug.js","../node_modules/@stdlib/utils-keys/lib/has_builtin.js","../node_modules/@stdlib/assert-is-arguments/lib/main.js","../node_modules/@stdlib/assert-is-arguments/lib/detect.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/has_string_enumerability_bug.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/native.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/main.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/index.js","../node_modules/@stdlib/assert-is-arguments/lib/polyfill.js","../node_modules/@stdlib/assert-is-arguments/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin_wrapper.js","../node_modules/@stdlib/utils-noop/lib/noop.js","../node_modules/@stdlib/utils-keys/lib/has_enumerable_prototype_bug.js","../node_modules/@stdlib/utils-keys/lib/has_non_enumerable_properties_bug.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype.js","../node_modules/@stdlib/utils-keys/lib/has_automation_equality_bug.js","../node_modules/@stdlib/utils-keys/lib/window.js","../node_modules/@stdlib/utils-keys/lib/has_window.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype_wrapper.js","../node_modules/@stdlib/utils-keys/lib/polyfill.js","../node_modules/@stdlib/utils-keys/lib/main.js","../node_modules/@stdlib/utils-keys/lib/index.js","../node_modules/@stdlib/utils-property-names/lib/has_builtin.js","../node_modules/@stdlib/utils-property-names/lib/builtin.js","../node_modules/@stdlib/utils-property-names/lib/polyfill.js","../node_modules/@stdlib/utils-property-names/lib/index.js","../node_modules/@stdlib/utils-property-descriptor/lib/has_builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/polyfill.js","../node_modules/@stdlib/utils-property-descriptor/lib/index.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/buffer.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/main.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/polyfill.js","../node_modules/@stdlib/buffer-ctor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/buffer.js","../node_modules/@stdlib/buffer-from-buffer/lib/has_from.js","../node_modules/@stdlib/buffer-from-buffer/lib/main.js","../node_modules/@stdlib/buffer-from-buffer/lib/polyfill.js","../node_modules/@stdlib/buffer-from-buffer/lib/index.js","../node_modules/@stdlib/assert-is-int8array/lib/main.js","../node_modules/@stdlib/assert-has-int8array-support/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/main.js","../node_modules/@stdlib/constants-int8-min/lib/index.js","../node_modules/@stdlib/array-int8/lib/polyfill.js","../node_modules/@stdlib/array-int8/lib/index.js","../node_modules/@stdlib/array-int8/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8array/lib/main.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/main.js","../node_modules/@stdlib/array-uint8/lib/polyfill.js","../node_modules/@stdlib/array-uint8/lib/index.js","../node_modules/@stdlib/array-uint8/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8clampedarray/lib/main.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/main.js","../node_modules/@stdlib/array-uint8c/lib/polyfill.js","../node_modules/@stdlib/array-uint8c/lib/index.js","../node_modules/@stdlib/array-uint8c/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/index.js","../node_modules/@stdlib/assert-is-int16array/lib/main.js","../node_modules/@stdlib/assert-has-int16array-support/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/main.js","../node_modules/@stdlib/constants-int16-min/lib/index.js","../node_modules/@stdlib/array-int16/lib/polyfill.js","../node_modules/@stdlib/array-int16/lib/index.js","../node_modules/@stdlib/array-int16/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint16array/lib/main.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/main.js","../node_modules/@stdlib/array-uint16/lib/polyfill.js","../node_modules/@stdlib/array-uint16/lib/index.js","../node_modules/@stdlib/array-uint16/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/index.js","../node_modules/@stdlib/assert-is-int32array/lib/main.js","../node_modules/@stdlib/assert-has-int32array-support/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/main.js","../node_modules/@stdlib/constants-int32-min/lib/index.js","../node_modules/@stdlib/array-int32/lib/polyfill.js","../node_modules/@stdlib/array-int32/lib/index.js","../node_modules/@stdlib/array-int32/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint32array/lib/main.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/main.js","../node_modules/@stdlib/array-uint32/lib/polyfill.js","../node_modules/@stdlib/array-uint32/lib/index.js","../node_modules/@stdlib/array-uint32/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float32array/lib/main.js","../node_modules/@stdlib/assert-has-float32array-support/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/main.js","../node_modules/@stdlib/array-float32/lib/polyfill.js","../node_modules/@stdlib/array-float32/lib/index.js","../node_modules/@stdlib/array-float32/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float64array/lib/main.js","../node_modules/@stdlib/assert-has-float64array-support/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/main.js","../node_modules/@stdlib/array-float64/lib/polyfill.js","../node_modules/@stdlib/array-float64/lib/index.js","../node_modules/@stdlib/array-float64/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/index.js","../node_modules/@stdlib/utils-copy/lib/typed_arrays.js","../node_modules/@stdlib/utils-copy/lib/deep_copy.js","../node_modules/@stdlib/utils-copy/lib/copy.js","../node_modules/@stdlib/utils-copy/lib/index.js","../node_modules/@stdlib/assert-is-object/lib/main.js","../node_modules/@stdlib/assert-is-plain-object/lib/main.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/validate.js","../node_modules/@stdlib/assert-is-plain-object/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/factory.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\nvar main = ( typeof Object.defineProperty === 'function' ) ? Object.defineProperty : null;\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar defineProperty = require( './define_property.js' );\n\n\n// MAIN //\n\n/**\n* Tests for `Object.defineProperty` support.\n*\n* @private\n* @returns {boolean} boolean indicating if an environment has `Object.defineProperty` support\n*\n* @example\n* var bool = hasDefinePropertySupport();\n* // returns \n*/\nfunction hasDefinePropertySupport() {\n\t// Test basic support...\n\ttry {\n\t\tdefineProperty( {}, 'x', {} );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasDefinePropertySupport;\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// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @name defineProperty\n* @type {Function}\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nvar defineProperty = Object.defineProperty;\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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/* eslint-disable no-underscore-dangle, no-proto */\n\n'use strict';\n\n// VARIABLES //\n\nvar objectProtoype = Object.prototype;\nvar toStr = objectProtoype.toString;\nvar defineGetter = objectProtoype.__defineGetter__;\nvar defineSetter = objectProtoype.__defineSetter__;\nvar lookupGetter = objectProtoype.__lookupGetter__;\nvar lookupSetter = objectProtoype.__lookupSetter__;\n\n\n// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @param {Object} obj - object on which to define the property\n* @param {string} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nfunction defineProperty( obj, prop, descriptor ) {\n\tvar prototype;\n\tvar hasValue;\n\tvar hasGet;\n\tvar hasSet;\n\n\tif ( typeof obj !== 'object' || obj === null || toStr.call( obj ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an object. Value: `' + obj + '`.' );\n\t}\n\tif ( typeof descriptor !== 'object' || descriptor === null || toStr.call( descriptor ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. Property descriptor must be an object. Value: `' + descriptor + '`.' );\n\t}\n\thasValue = ( 'value' in descriptor );\n\tif ( hasValue ) {\n\t\tif (\n\t\t\tlookupGetter.call( obj, prop ) ||\n\t\t\tlookupSetter.call( obj, prop )\n\t\t) {\n\t\t\t// Override `__proto__` to avoid touching inherited accessors:\n\t\t\tprototype = obj.__proto__;\n\t\t\tobj.__proto__ = objectProtoype;\n\n\t\t\t// Delete property as existing getters/setters prevent assigning value to specified property:\n\t\t\tdelete obj[ prop ];\n\t\t\tobj[ prop ] = descriptor.value;\n\n\t\t\t// Restore original prototype:\n\t\t\tobj.__proto__ = prototype;\n\t\t} else {\n\t\t\tobj[ prop ] = descriptor.value;\n\t\t}\n\t}\n\thasGet = ( 'get' in descriptor );\n\thasSet = ( 'set' in descriptor );\n\n\tif ( hasValue && ( hasGet || hasSet ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.' );\n\t}\n\n\tif ( hasGet && defineGetter ) {\n\t\tdefineGetter.call( obj, prop, descriptor.get );\n\t}\n\tif ( hasSet && defineSetter ) {\n\t\tdefineSetter.call( obj, prop, descriptor.set );\n\t}\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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* Define (or modify) an object property.\n*\n* @module @stdlib/utils-define-property\n*\n* @example\n* var defineProperty = require( '@stdlib/utils-define-property' );\n*\n* var obj = {};\n* defineProperty( obj, 'foo', {\n* 'value': 'bar',\n* 'writable': false,\n* 'configurable': false,\n* 'enumerable': false\n* });\n* obj.foo = 'boop'; // => throws\n*/\n\n// MODULES //\n\nvar hasDefinePropertySupport = require( './has_define_property_support.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar defineProperty;\nif ( hasDefinePropertySupport() ) {\n\tdefineProperty = builtin;\n} else {\n\tdefineProperty = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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\nvar defineProperty = require( '@stdlib/utils-define-property' );\n\n\n// MAIN //\n\n/**\n* Defines a non-enumerable read-only property.\n*\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setNonEnumerableReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Define a non-enumerable read-only property.\n*\n* @module @stdlib/utils-define-nonenumerable-read-only-property\n*\n* @example\n* var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\n*\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\n\n// MODULES //\n\nvar setNonEnumerableReadOnly = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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// MAIN //\n\n/**\n* Tests for native `Symbol` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Symbol` support\n*\n* @example\n* var bool = hasSymbolSupport();\n* // returns \n*/\nfunction hasSymbolSupport() {\n\treturn (\n\t\ttypeof Symbol === 'function' &&\n\t\ttypeof Symbol( 'foo' ) === 'symbol'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasSymbolSupport;\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\nvar hasSymbols = require( '@stdlib/assert-has-symbol-support' );\n\n\n// VARIABLES //\n\nvar FLG = hasSymbols();\n\n\n// MAIN //\n\n/**\n* Tests for native `toStringTag` support.\n*\n* @returns {boolean} boolean indicating if an environment has `toStringTag` support\n*\n* @example\n* var bool = hasToStringTagSupport();\n* // returns \n*/\nfunction hasToStringTagSupport() {\n\treturn ( FLG && typeof Symbol.toStringTag === 'symbol' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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* Test for native `toStringTag` support.\n*\n* @module @stdlib/assert-has-tostringtag-support\n*\n* @example\n* var hasToStringTagSupport = require( '@stdlib/assert-has-tostringtag-support' );\n*\n* var bool = hasToStringTagSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasToStringTagSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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// MAIN //\n\nvar toStr = Object.prototype.toString;\n\n\n// EXPORTS //\n\nmodule.exports = toStr;\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\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification (via the internal property `[[Class]]`) of an object.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\treturn toStr.call( v );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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// FUNCTIONS //\n\nvar has = Object.prototype.hasOwnProperty;\n\n\n// MAIN //\n\n/**\n* Tests if an object has a specified property.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object has a specified property\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'bap' );\n* // returns false\n*/\nfunction hasOwnProp( value, property ) {\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\treturn has.call( value, property );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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* Test whether an object has a specified property.\n*\n* @module @stdlib/assert-has-own-property\n*\n* @example\n* var hasOwnProp = require( '@stdlib/assert-has-own-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* bool = hasOwnProp( beep, 'bop' );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasOwnProp = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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// MAIN //\n\nvar toStrTag = ( typeof Symbol === 'function' ) ? Symbol.toStringTag : '';\n\n\n// EXPORTS //\n\nmodule.exports = toStrTag;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar toStringTag = require( './tostringtag.js' );\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification of an object in environments supporting `Symbol.toStringTag`.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\tvar isOwn;\n\tvar tag;\n\tvar out;\n\n\tif ( v === null || v === void 0 ) {\n\t\treturn toStr.call( v );\n\t}\n\ttag = v[ toStringTag ];\n\tisOwn = hasOwnProp( v, toStringTag );\n\n\t// Attempt to override the `toStringTag` property. For built-ins having a `Symbol.toStringTag` property (e.g., `JSON`, `Math`, etc), the `Symbol.toStringTag` property is read-only (e.g., , so we need to wrap in a `try/catch`.\n\ttry {\n\t\tv[ toStringTag ] = void 0;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn toStr.call( v );\n\t}\n\tout = toStr.call( v );\n\n\tif ( isOwn ) {\n\t\tv[ toStringTag ] = tag;\n\t} else {\n\t\tdelete v[ toStringTag ];\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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* Return a string value indicating a specification defined classification of an object.\n*\n* @module @stdlib/utils-native-class\n*\n* @example\n* var nativeClass = require( '@stdlib/utils-native-class' );\n*\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* function Beep() {\n* return this;\n* }\n* str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\n\n// MODULES //\n\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar builtin = require( './native_class.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar nativeClass;\nif ( hasToStringTag() ) {\n\tnativeClass = polyfill;\n} else {\n\tnativeClass = builtin;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to extract a string value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a string can be extracted\n*/\nfunction test( value ) {\n\ttry {\n\t\tvalueOf.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar valueOf = String.prototype.valueOf; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2valueof.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string object\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns false\n*/\nfunction isString( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof String ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object String]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a string\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*/\nfunction isString( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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* Test if a value is a string.\n*\n* @module @stdlib/assert-is-string\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' );\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 5 );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isObject;\n*\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 'beep' );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isString = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isString, 'isPrimitive', isPrimitive );\nsetReadOnly( isString, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// VARIABLES //\n\nvar RE_CHARS = /[-\\/\\\\^$*+?.()|[\\]{}]/g; // eslint-disable-line no-useless-escape\n\n\n// MAIN //\n\n/**\n* Escapes a regular expression string.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} first argument must be a string primitive\n* @returns {string} escaped string\n*\n* @example\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\nfunction rescape( str ) {\n\tvar len;\n\tvar s;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Check if the string starts with a forward slash...\n\tif ( str[ 0 ] === '/' ) {\n\t\t// Find the last forward slash...\n\t\tlen = str.length;\n\t\tfor ( i = len-1; i >= 0; i-- ) {\n\t\t\tif ( str[ i ] === '/' ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:\n\tif ( i === void 0 || i <= 0 ) {\n\t\treturn str.replace( RE_CHARS, '\\\\$&' );\n\t}\n\t// We need to de-construct the string...\n\ts = str.substring( 1, i );\n\n\t// Only escape the characters between the `/`:\n\ts = s.replace( RE_CHARS, '\\\\$&' );\n\n\t// Reassemble:\n\tstr = str[ 0 ] + s + str.substring( i );\n\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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* Escape a regular expression string or pattern.\n*\n* @module @stdlib/utils-escape-regexp-string\n*\n* @example\n* var rescape = require( '@stdlib/utils-escape-regexp-string' );\n*\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\n\n// MODULES //\n\nvar rescape = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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\nvar RE = /./;\n\n\n// EXPORTS //\n\nmodule.exports = RE;\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* Tests if a value is a boolean primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean primitive\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns false\n*/\nfunction isBoolean( value ) {\n\treturn ( typeof value === 'boolean' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Boolean.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean object\n*\n* @example\n* var bool = isBoolean( true );\n* // returns false\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Boolean ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Boolean]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a boolean\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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* Test if a value is a boolean.\n*\n* @module @stdlib/assert-is-boolean\n*\n* @example\n* var isBoolean = require( '@stdlib/assert-is-boolean' );\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* // Use interface to check for boolean primitives...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( true ) );\n* // returns false\n*\n* @example\n* // Use interface to check for boolean objects...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isObject;\n*\n* var bool = isBoolean( true );\n* // returns false\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isBoolean = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isBoolean, 'isPrimitive', isPrimitive );\nsetReadOnly( isBoolean, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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// MAIN //\n\n/**\n* Returns the global object using code generation.\n*\n* @private\n* @returns {Object} global object\n*/\nfunction getGlobal() {\n\treturn new Function( 'return this;' )(); // eslint-disable-line no-new-func\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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// MAIN //\n\nvar obj = ( typeof self === 'object' ) ? self : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof window === 'object' ) ? window : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof global === 'object' ) ? global : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar getThis = require( './codegen.js' );\nvar Self = require( './self.js' );\nvar Win = require( './window.js' );\nvar Global = require( './global.js' );\n\n\n// MAIN //\n\n/**\n* Returns the global object.\n*\n* ## Notes\n*\n* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.\n*\n* @param {boolean} [codegen=false] - boolean indicating whether to use code generation to resolve the global object\n* @throws {TypeError} must provide a boolean\n* @throws {Error} unable to resolve global object\n* @returns {Object} global object\n*\n* @example\n* var g = getGlobal();\n* // returns {...}\n*/\nfunction getGlobal( codegen ) {\n\tif ( arguments.length ) {\n\t\tif ( !isBoolean( codegen ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Must provide a boolean primitive. Value: `'+codegen+'`.' );\n\t\t}\n\t\tif ( codegen ) {\n\t\t\treturn getThis();\n\t\t}\n\t\t// Fall through...\n\t}\n\t// Case: browsers and web workers\n\tif ( Self ) {\n\t\treturn Self;\n\t}\n\t// Case: browsers\n\tif ( Win ) {\n\t\treturn Win;\n\t}\n\t// Case: Node.js\n\tif ( Global ) {\n\t\treturn Global;\n\t}\n\t// Case: unknown\n\tthrow new Error( 'unexpected error. Unable to resolve global object.' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar getGlobal = require( '@stdlib/utils-global' );\n\n\n// MAIN //\n\nvar root = getGlobal();\nvar nodeList = root.document && root.document.childNodes;\n\n\n// EXPORTS //\n\nmodule.exports = nodeList;\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* Return the global object.\n*\n* @module @stdlib/utils-global\n*\n* @example\n* var getGlobal = require( '@stdlib/utils-global' );\n*\n* var g = getGlobal();\n* // returns {...}\n*/\n\n// MODULES //\n\nvar getGlobal = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar typedarray = Int8Array; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = typedarray;\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\nvar RE = require( './fixtures/re.js' );\nvar nodeList = require( './fixtures/nodelist.js' );\nvar typedarray = require( './fixtures/typedarray.js' );\n\n\n// MAIN //\n\n/**\n* Checks whether a polyfill is needed when using the `typeof` operator.\n*\n* @private\n* @returns {boolean} boolean indicating whether a polyfill is needed\n*/\nfunction check() {\n\tif (\n\t\t// Chrome 1-12 returns 'function' for regular expression instances (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof):\n\t\ttypeof RE === 'function' ||\n\n\t\t// Safari 8 returns 'object' for typed array and weak map constructors (underscore #1929):\n\t\ttypeof typedarray === 'object' ||\n\n\t\t// PhantomJS 1.9 returns 'function' for `NodeList` instances (underscore #2236):\n\t\ttypeof nodeList === 'function'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\nfunction reFunctionName() {\n\treturn /^\\s*function\\s*([^(]*)/i;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @module @stdlib/regexp-function-name\n*\n* @example\n* var reFunctionName = require( '@stdlib/regexp-function-name' );\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reFunctionName = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reFunctionName, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\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\nvar reFunctionName = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Captures everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* Regular expression: `/^\\s*function\\s*([^(]*)/i`\n*\n* - `/^\\s*`\n* - Match zero or more spaces at beginning\n*\n* - `function`\n* - Match the word `function`\n*\n* - `\\s*`\n* - Match zero or more spaces after the word `function`\n*\n* - `()`\n* - Capture\n*\n* - `[^(]*`\n* - Match anything except a left parenthesis `(` zero or more times\n*\n* - `/i`\n* - ignore case\n*\n* @constant\n* @type {RegExp}\n* @default /^\\s*function\\s*([^(]*)/i\n*/\nvar RE_FUNCTION_NAME = reFunctionName();\n\n\n// EXPORTS //\n\nmodule.exports = RE_FUNCTION_NAME;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar f;\n\n\n// FUNCTIONS //\n\n/**\n* Tests if a value is an array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an array\n*\n* @example\n* var bool = isArray( [] );\n* // returns true\n*\n* @example\n* var bool = isArray( {} );\n* // returns false\n*/\nfunction isArray( value ) {\n\treturn ( nativeClass( value ) === '[object Array]' );\n}\n\n\n// MAIN //\n\nif ( Array.isArray ) {\n\tf = Array.isArray;\n} else {\n\tf = isArray;\n}\n\n\n// EXPORTS //\n\nmodule.exports = f;\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* Test if a value is an array.\n*\n* @module @stdlib/assert-is-array\n*\n* @example\n* var isArray = require( '@stdlib/assert-is-array' );\n*\n* var bool = isArray( [] );\n* // returns true\n*\n* bool = isArray( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isArray = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isArray;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Returns a function which tests if every element in an array passes a test condition.\n*\n* @param {Function} predicate - function to apply\n* @throws {TypeError} must provide a function\n* @returns {Function} an array function\n*\n* @example\n* var isOdd = require( '@stdlib/assert-is-odd' );\n*\n* var arr1 = [ 1, 3, 5, 7 ];\n* var arr2 = [ 3, 5, 8 ];\n*\n* var validate = arrayfcn( isOdd );\n*\n* var bool = validate( arr1 );\n* // returns true\n*\n* bool = validate( arr2 );\n* // returns false\n*/\nfunction arrayfcn( predicate ) {\n\tif ( typeof predicate !== 'function' ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a function. Value: `' + predicate + '`.' );\n\t}\n\treturn every;\n\n\t/**\n\t* Tests if every element in an array passes a test condition.\n\t*\n\t* @private\n\t* @param {*} value - value to test\n\t* @returns {boolean} boolean indicating whether a value is an array for which all elements pass a test condition\n\t*/\n\tfunction every( value ) {\n\t\tvar len;\n\t\tvar i;\n\t\tif ( !isArray( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tlen = value.length;\n\t\tif ( len === 0 ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( predicate( value[ i ] ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayfcn;\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* Tests if a value is object-like.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is object-like\n*\n* @example\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( [] );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( null );\n* // returns false\n*/\nfunction isObjectLike( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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* Test if a value is object-like.\n*\n* @module @stdlib/assert-is-object-like\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' );\n*\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* bool = isObjectLike( [] );\n* // returns true\n*\n* bool = isObjectLike( null );\n* // returns false\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' ).isObjectLikeArray;\n*\n* var bool = isObjectLike( [ {}, [] ] );\n* // returns true\n*\n* bool = isObjectLike( [ {}, '3.0' ] );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar arrayfun = require( '@stdlib/assert-tools-array-function' );\nvar isObjectLike = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( isObjectLike, 'isObjectLikeArray', arrayfun( isObjectLike ) );\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Buffer instance.\n*\n* @param {*} value - value to validate\n* @returns {boolean} boolean indicating if a value is a Buffer instance\n*\n* @example\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( new Buffer( [1,2,3,4] ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( {} );\n* // returns false\n*\n* @example\n* var v = isBuffer( [] );\n* // returns false\n*/\nfunction isBuffer( value ) {\n\treturn (\n\t\tisObjectLike( value ) &&\n\t\t(\n\t\t\t// eslint-disable-next-line no-underscore-dangle\n\t\t\tvalue._isBuffer || // for envs missing Object.prototype.constructor (e.g., Safari 5-7)\n\t\t\t(\n\t\t\t\tvalue.constructor &&\n\n\t\t\t\t// WARNING: `typeof` is not a foolproof check, as certain envs consider RegExp and NodeList instances to be functions\n\t\t\t\ttypeof value.constructor.isBuffer === 'function' &&\n\t\t\t\tvalue.constructor.isBuffer( value )\n\t\t\t)\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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* Test if a value is a Buffer instance.\n*\n* @module @stdlib/assert-is-buffer\n*\n* @example\n* var isBuffer = require( '@stdlib/assert-is-buffer' );\n*\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* v = isBuffer( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isBuffer = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar RE = require( '@stdlib/regexp-function-name' ).REGEXP;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\n\n\n// MAIN //\n\n/**\n* Determines the name of a value's constructor.\n*\n* @param {*} v - input value\n* @returns {string} name of a value's constructor\n*\n* @example\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* @example\n* var v = constructorName( 5 );\n* // returns 'Number'\n*\n* @example\n* var v = constructorName( null );\n* // returns 'Null'\n*\n* @example\n* var v = constructorName( undefined );\n* // returns 'Undefined'\n*\n* @example\n* var v = constructorName( function noop() {} );\n* // returns 'Function'\n*/\nfunction constructorName( v ) {\n\tvar match;\n\tvar name;\n\tvar ctor;\n\tname = nativeClass( v ).slice( 8, -1 );\n\tif ( (name === 'Object' || name === 'Error') && v.constructor ) {\n\t\tctor = v.constructor;\n\t\tif ( typeof ctor.name === 'string' ) {\n\t\t\treturn ctor.name;\n\t\t}\n\t\tmatch = RE.exec( ctor.toString() );\n\t\tif ( match ) {\n\t\t\treturn match[ 1 ];\n\t\t}\n\t}\n\tif ( isBuffer( v ) ) {\n\t\treturn 'Buffer';\n\t}\n\treturn name;\n}\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// NOTES //\n\n/*\n* Built-in `typeof` operator behavior:\n*\n* ```text\n* typeof null => 'object'\n* typeof undefined => 'undefined'\n* typeof 'a' => 'string'\n* typeof 5 => 'number'\n* typeof NaN => 'number'\n* typeof true => 'boolean'\n* typeof false => 'boolean'\n* typeof {} => 'object'\n* typeof [] => 'object'\n* typeof function foo(){} => 'function'\n* typeof function* foo(){} => 'object'\n* typeof Symbol() => 'symbol'\n* ```\n*\n*/\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\tvar type;\n\n\t// Address `typeof null` => `object` (see http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null):\n\tif ( v === null ) {\n\t\treturn 'null';\n\t}\n\ttype = typeof v;\n\n\t// If the `typeof` operator returned something other than `object`, we are done. Otherwise, we need to check for an internal class name or search for a constructor.\n\tif ( type === 'object' ) {\n\t\treturn ctorName( v ).toLowerCase();\n\t}\n\treturn type;\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine the name of a value's constructor.\n*\n* @module @stdlib/utils-constructor-name\n*\n* @example\n* var constructorName = require( '@stdlib/utils-constructor-name' );\n*\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* v = constructorName( {} );\n* // returns 'Object'\n*\n* v = constructorName( true );\n* // returns 'Boolean'\n*/\n\n// MODULES //\n\nvar constructorName = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\treturn ctorName( v ).toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine a value's type.\n*\n* @module @stdlib/utils-type-of\n*\n* @example\n* var typeOf = require( '@stdlib/utils-type-of' );\n*\n* var str = typeOf( 'a' );\n* // returns 'string'\n*\n* str = typeOf( 5 );\n* // returns 'number'\n*/\n\n// MODULES //\n\nvar usePolyfill = require( './check.js' );\nvar typeOf = require( './typeof.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main = ( usePolyfill() ) ? polyfill : typeOf;\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar typeOf = require( '@stdlib/utils-type-of' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a function.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a function\n*\n* @example\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\nfunction isFunction( value ) {\n\t// Note: cannot use `typeof` directly, as various browser engines incorrectly return `'function'` when operating on non-function objects, such as regular expressions and NodeLists.\n\treturn ( typeOf( value ) === 'function' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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* Test if a value is a function.\n*\n* @module @stdlib/assert-is-function\n*\n* @example\n* var isFunction = require( '@stdlib/assert-is-function' );\n*\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\n\n// MODULES //\n\nvar isFunction = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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\nvar exec = require( './exec.js' );\n\n\n// MAIN //\n\n/**\n* Attempts to call a `RegExp` method.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if able to call a `RegExp` method\n*/\nfunction test( value ) {\n\ttry {\n\t\texec.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar exec = RegExp.prototype.exec; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = exec;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2exec.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a regular expression.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a regular expression\n*\n* @example\n* var bool = isRegExp( /\\.+/ );\n* // returns true\n*\n* @example\n* var bool = isRegExp( {} );\n* // returns false\n*/\nfunction isRegExp( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof RegExp ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object RegExp]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isRegExp;\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\nvar rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument argument must be a string primitive or regular expression\n* @throws {TypeError} third argument must be a string primitive or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive or regular expression. Value: `' + search + '`.' );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( 'invalid argument. Third argument must be a string primitive or replacement function. Value: `' + newval + '`.' );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Constructor which returns a `Number` object.\n*\n* @module @stdlib/number-ctor\n*\n* @example\n* var Number = require( '@stdlib/number-ctor' );\n*\n* var v = new Number( 10.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar Number = require( './number.js' );\n\n\n// EXPORTS //\n\nmodule.exports = Number;\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// EXPORTS //\n\nmodule.exports = Number; // eslint-disable-line stdlib/require-globals\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Number.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar Number = require( '@stdlib/number-ctor' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\nfunction isNumber( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Number ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Number]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a number\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( null );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Test if a value is a number.\n*\n* @module @stdlib/assert-is-number\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' );\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( null );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isObject;\n*\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNumber, 'isPrimitive', isPrimitive );\nsetReadOnly( isNumber, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Double-precision floating-point positive infinity.\n*\n* @module @stdlib/constants-float64-pinf\n* @type {number}\n*\n* @example\n* var FLOAT64_PINF = require( '@stdlib/constants-float64-pinf' );\n* // returns Infinity\n*/\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point positive infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point positive infinity has the bit sequence\n*\n* ```binarystring\n* 0 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.POSITIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_PINF = Number.POSITIVE_INFINITY; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_PINF;\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* Double-precision floating-point negative infinity.\n*\n* @module @stdlib/constants-float64-ninf\n* @type {number}\n*\n* @example\n* var FLOAT64_NINF = require( '@stdlib/constants-float64-ninf' );\n* // returns -Infinity\n*/\n\n// MODULES //\n\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point negative infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point negative infinity has the bit sequence\n*\n* ```binarystring\n* 1 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.NEGATIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_NINF = Number.NEGATIVE_INFINITY;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_NINF;\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\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Tests if a finite double-precision floating-point number is an integer.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\treturn (floor(x) === x);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// TODO: implementation (?)\n\n/**\n* Rounds a double-precision floating-point number toward negative infinity.\n*\n* @param {number} x - input value\n* @returns {number} rounded value\n*\n* @example\n* var v = floor( -4.2 );\n* // returns -5.0\n*\n* @example\n* var v = floor( 9.99999 );\n* // returns 9.0\n*\n* @example\n* var v = floor( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = floor( NaN );\n* // returns NaN\n*/\nvar floor = Math.floor; // eslint-disable-line stdlib/no-builtin-math\n\n\n// EXPORTS //\n\nmodule.exports = floor;\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* Test if a finite double-precision floating-point number is an integer.\n*\n* @module @stdlib/math-base-assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/math-base-assert-is-integer' );\n*\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* bool = isInteger( 3.14 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isInteger = require( './is_integer.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar isInt = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests if a number primitive is an integer value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a number primitive is an integer value\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tvalue < PINF &&\n\t\tvalue > NINF &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having an integer value\n*\n* @example\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having an integer value\n*\n* @example\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an integer\n*\n* @example\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isInteger( -3.14 );\n* // returns false\n*\n* @example\n* var bool = isInteger( null );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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* Test if a value is an integer.\n*\n* @module @stdlib/assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/assert-is-integer' );\n*\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isInteger( -3.14 );\n* // returns false\n*\n* bool = isInteger( null );\n* // returns false\n*\n* @example\n* // Use interface to check for integer primitives...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n*\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*\n* @example\n* // Use interface to check for integer objects...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n*\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue.valueOf() >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a nonnegative integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a nonnegative integer\n*\n* @example\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( null );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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* Test if a value is a nonnegative integer.\n*\n* @module @stdlib/assert-is-nonnegative-integer\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' );\n*\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* bool = isNonNegativeInteger( null );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isObject;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNonNegativeInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isNonNegativeInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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// MAIN //\n\nvar getProto = Object.getPrototypeOf;\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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* Returns the value of the `__proto__` property.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {*} value of `__proto__` property\n*/\nfunction getProto( obj ) {\n\t// eslint-disable-next-line no-proto\n\treturn obj.__proto__;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar getProto = require( './proto.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {(Object|null)} prototype\n*/\nfunction getPrototypeOf( obj ) {\n\tvar proto = getProto( obj );\n\tif ( proto || proto === null ) {\n\t\treturn proto;\n\t}\n\tif ( nativeClass( obj.constructor ) === '[object Function]' ) {\n\t\t// May break if the constructor has been tampered with...\n\t\treturn obj.constructor.prototype;\n\t}\n\tif ( obj instanceof Object ) {\n\t\treturn Object.prototype;\n\t}\n\t// Return `null` for objects created via `Object.create( null )`. Also return `null` for cross-realm objects on browsers that lack `__proto__` support, such as IE < 11.\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar builtin = require( './native.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar getProto;\nif ( isFunction( Object.getPrototypeOf ) ) {\n\tgetProto = builtin;\n} else {\n\tgetProto = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar getProto = require( './detect.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @param {*} value - input value\n* @returns {(Object|null)} prototype\n*\n* @example\n* var proto = getPrototypeOf( {} );\n* // returns {}\n*/\nfunction getPrototypeOf( value ) {\n\tif (\n\t\tvalue === null ||\n\t\tvalue === void 0\n\t) {\n\t\treturn null;\n\t}\n\t// In order to ensure consistent ES5/ES6 behavior, cast input value to an object (strings, numbers, booleans); ES5 `Object.getPrototypeOf` throws when provided primitives and ES6 `Object.getPrototypeOf` casts:\n\tvalue = Object( value );\n\n\treturn getProto( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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* Return the prototype of a provided object.\n*\n* @module @stdlib/utils-get-prototype-of\n*\n* @example\n* var getPrototype = require( '@stdlib/utils-get-prototype-of' );\n*\n* var proto = getPrototype( {} );\n* // returns {}\n*/\n\n// MODULES //\n\nvar getPrototype = require( './get_prototype_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getPrototype;\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\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an `Error` object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `Error` object\n*\n* @example\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isError( {} );\n* // returns false\n*/\nfunction isError( value ) {\n\tif ( typeof value !== 'object' || value === null ) {\n\t\treturn false;\n\t}\n\t// Check for `Error` objects from the same realm (same Node.js `vm` or same `Window` object)...\n\tif ( value instanceof Error ) {\n\t\treturn true;\n\t}\n\t// Walk the prototype tree until we find an object having the desired native class...\n\twhile ( value ) {\n\t\tif ( nativeClass( value ) === '[object Error]' ) {\n\t\t\treturn true;\n\t\t}\n\t\tvalue = getPrototypeOf( value );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isError;\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* Test if a value is an `Error` object.\n*\n* @module @stdlib/assert-is-error\n*\n* @example\n* var isError = require( '@stdlib/assert-is-error' );\n*\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* bool = isError( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isError = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isError;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to parse a regular expression string.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*/\nfunction reRegExp() {\n\treturn /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/; // eslint-disable-line no-useless-escape\n}\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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* Return a regular expression to parse a regular expression string.\n*\n* @module @stdlib/regexp-regexp\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var parts = RE_REGEXP.exec( '/^.*$/ig' );\n* // returns [ '/^.*$/ig', '^.*$', 'ig', 'index': 0, 'input': '/^.*$/ig' ]\n*/\n\n// MAIN //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reRegExp = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reRegExp, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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\nvar reRegExp = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Matches parts of a regular expression string.\n*\n* Regular expression: `/^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/`\n*\n* - `/^\\/`\n* - match a string that begins with a `/`\n*\n* - `()`\n* - capture\n*\n* - `(?:)+`\n* - capture, but do not remember, a group of characters which occur one or more times\n*\n* - `\\\\\\/`\n* - match the literal `\\/`\n*\n* - `|`\n* - OR\n*\n* - `[^\\/]`\n* - anything which is not the literal `\\/`\n*\n* - `\\/`\n* - match the literal `/`\n*\n* - `([imgy]*)`\n* - capture any characters matching `imgy` occurring zero or more times\n*\n* - `$/`\n* - string end\n*\n*\n* @constant\n* @type {RegExp}\n* @default /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/\n*/\nvar RE_REGEXP = reRegExp();\n\n\n// EXPORTS //\n\nmodule.exports = RE_REGEXP;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar reRegExp = require( '@stdlib/regexp-regexp' );\n\n\n// MAIN //\n\n/**\n* Parses a regular expression string and returns a new regular expression.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} must provide a regular expression string\n* @returns {(RegExp|null)} regular expression or null\n*\n* @example\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\nfunction reFromString( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Capture the regular expression pattern and any flags:\n\tstr = reRegExp().exec( str );\n\n\t// Create a new regular expression:\n\treturn ( str ) ? new RegExp( str[1], str[2] ) : null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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* Create a regular expression from a regular expression string.\n*\n* @module @stdlib/utils-regexp-from-string\n*\n* @example\n* var reFromString = require( '@stdlib/utils-regexp-from-string' );\n*\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\n\n// MODULES //\n\nvar reFromString = require( './from_string.js' );\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is `NaN`.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 7.0 );\n* // returns false\n*/\nfunction isnan( x ) {\n\treturn ( x !== x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a `NaN` number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a `NaN` number primitive\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a double-precision floating-point numeric value is `NaN`.\n*\n* @module @stdlib/math-base-assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/math-base-assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 7.0 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isnan = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a value of `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a value of `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( null );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a value is `NaN`.\n*\n* @module @stdlib/assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( null );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isObject;\n*\n* var bool = isnan( NaN );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isnan = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isnan, 'isPrimitive', isPrimitive );\nsetReadOnly( isnan, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a collection.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is a collection\n*\n* @example\n* var bool = isCollection( [] );\n* // returns true\n*\n* @example\n* var bool = isCollection( {} );\n* // returns false\n*/\nfunction isCollection( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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\nvar isnan = require( '@stdlib/assert-is-nan' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Returns the first index at which a given element can be found.\n*\n* @param {ArrayLike} arr - array-like object\n* @param {*} searchElement - element to find\n* @param {integer} [fromIndex] - starting index (if negative, the start index is determined relative to last element)\n* @throws {TypeError} must provide an array-like object\n* @throws {TypeError} `fromIndex` must be an integer\n* @returns {integer} index or -1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 5 );\n* // returns -1\n*\n* @example\n* // Using a `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* @example\n* // `fromIndex` which exceeds `array` length:\n* var arr = [ 1, 2, 3, 4, 2, 5 ];\n* var idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* @example\n* // Negative `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* var idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* @example\n* // Negative `fromIndex` exceeding input `array` length:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* @example\n* // Array-like objects:\n* var str = 'bebop';\n* var idx = indexOf( str, 'o' );\n* // returns 3\n*/\nfunction indexOf( arr, searchElement, fromIndex ) {\n\tvar len;\n\tvar i;\n\tif ( !isCollection( arr ) && !isString( arr ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array-like object. Value: `' + arr + '`.' );\n\t}\n\tlen = arr.length;\n\tif ( len === 0 ) {\n\t\treturn -1;\n\t}\n\tif ( arguments.length === 3 ) {\n\t\tif ( !isInteger( fromIndex ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `fromIndex` must be an integer. Value: `' + fromIndex + '`.' );\n\t\t}\n\t\tif ( fromIndex >= 0 ) {\n\t\t\tif ( fromIndex >= len ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\ti = fromIndex;\n\t\t} else {\n\t\t\ti = len + fromIndex;\n\t\t\tif ( i < 0 ) {\n\t\t\t\ti = 0;\n\t\t\t}\n\t\t}\n\t} else {\n\t\ti = 0;\n\t}\n\t// Check for `NaN`...\n\tif ( isnan( searchElement ) ) {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( isnan( arr[i] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( arr[ i ] === searchElement ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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* Maximum length of a typed array.\n*\n* @module @stdlib/constants-array-max-typed-array-length\n*\n* @example\n* var MAX_TYPED_ARRAY_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n* // returns 9007199254740991\n*/\n\n// MAIN //\n\n/**\n* Maximum length of a typed array.\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n*/\nvar MAX_TYPED_ARRAY_LENGTH = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = MAX_TYPED_ARRAY_LENGTH;\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* Return the first index at which a given element can be found.\n*\n* @module @stdlib/utils-index-of\n*\n* @example\n* var indexOf = require( '@stdlib/utils-index-of' );\n*\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* arr = [ 4, 3, 2, 1 ];\n* idx = indexOf( arr, 5 );\n* // returns -1\n*\n* // Using a `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* // `fromIndex` which exceeds `array` length:\n* arr = [ 1, 2, 3, 4, 2, 5 ];\n* idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* // Negative `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* // Negative `fromIndex` exceeding input `array` length:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* // Array-like objects:\n* var str = 'bebop';\n* idx = indexOf( str, 'o' );\n* // returns 3\n*/\n\n// MODULES //\n\nvar indexOf = require( './index_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.keys()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\treturn Object.keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar keys = require( './builtin.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests the built-in `Object.keys()` implementation when provided `arguments`.\n*\n* @private\n* @returns {boolean} boolean indicating whether the built-in implementation returns the expected number of keys\n*/\nfunction test() {\n\treturn ( keys( arguments ) || '' ).length !== 2;\n}\n\n\n// MAIN //\n\n/**\n* Tests whether the built-in `Object.keys()` implementation supports providing `arguments` as an input value.\n*\n* ## Notes\n*\n* - Safari 5.0 does **not** support `arguments` as an input value.\n*\n* @private\n* @returns {boolean} boolean indicating whether a built-in implementation supports `arguments`\n*/\nfunction check() {\n\treturn test( 1, 2 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\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// MAIN //\n\nvar bool = ( typeof Object.keys !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn ( nativeClass( value ) === '[object Arguments]' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( './main.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment returns the expected internal class of the `arguments` object.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment behaves as expected\n*\n* @example\n* var bool = detect();\n* // returns \n*/\nfunction detect() {\n\treturn isArguments( arguments );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnum = require( './native.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment has a bug where String indices are not detected as \"enumerable\" properties. Observed in Node v0.10.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment has the bug\n*/\nfunction detect() {\n\treturn !isEnum.call( 'beep', '0' );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @private\n* @name isEnumerableProperty\n* @type {Function}\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nvar isEnumerableProperty = Object.prototype.propertyIsEnumerable;\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar isString = require( '@stdlib/assert-is-string' );\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isEnum = require( './native.js' );\nvar hasStringEnumBug = require( './has_string_enumerability_bug.js' );\n\n\n// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nfunction isEnumerableProperty( value, property ) {\n\tvar bool;\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\tbool = isEnum.call( value, property );\n\tif ( !bool && hasStringEnumBug && isString( value ) ) {\n\t\t// Note: we only check for indices, as properties attached to a `String` object are properly detected as enumerable above.\n\t\tproperty = +property;\n\t\treturn (\n\t\t\t!isnan( property ) &&\n\t\t\tisInteger( property ) &&\n\t\t\tproperty >= 0 &&\n\t\t\tproperty < value.length\n\t\t);\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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* Test whether an object's own property is enumerable.\n*\n* @module @stdlib/assert-is-enumerable-property\n*\n* @example\n* var isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\n\n// MODULES //\n\nvar isEnumerableProperty = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-uint32-max' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object' &&\n\t\t!isArray( value ) &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH &&\n\t\thasOwnProp( value, 'callee' ) &&\n\t\t!isEnumerableProperty( value, 'callee' )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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* Test if a value is an `arguments` object.\n*\n* @module @stdlib/assert-is-arguments\n*\n* @example\n* var isArguments = require( '@stdlib/assert-is-arguments' );\n*\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* bool = isArguments( [] );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasArgumentsClass = require( './detect.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar isArguments;\nif ( hasArgumentsClass ) {\n\tisArguments = main;\n} else {\n\tisArguments = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar builtin = require( './builtin.js' );\n\n\n// VARIABLES //\n\nvar slice = Array.prototype.slice;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tif ( isArguments( value ) ) {\n\t\treturn builtin( slice.call( value ) );\n\t}\n\treturn builtin( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* No operation.\n*\n* @example\n* noop();\n* // ...does nothing.\n*/\nfunction noop() {\n\t// Empty function...\n}\n\n\n// EXPORTS //\n\nmodule.exports = noop;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar noop = require( '@stdlib/utils-noop' );\n\n\n// MAIN //\n\n// Note: certain environments treat an object's prototype as enumerable, which, as a matter of convention, it shouldn't be...\nvar bool = isEnumerableProperty( noop, 'prototype' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n\n\n// VARIABLES //\n\nvar obj = {\n\t'toString': null\n};\n\n\n// MAIN //\n\n// Note: certain environments don't allow enumeration of overwritten properties which are considered non-enumerable...\nvar bool = !isEnumerableProperty( obj, 'toString' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests whether a value equals the prototype of its constructor.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction isConstructorPrototype( value ) {\n\treturn ( value.constructor && value.constructor.prototype === value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isConstructorPrototype;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar EXCLUDED_KEYS = require( './excluded_keys.json' );\nvar win = require( './window.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Determines whether an environment throws when comparing to the prototype of a value's constructor (e.g., [IE9][1]).\n*\n* [1]: https://stackoverflow.com/questions/7688070/why-is-comparing-the-constructor-property-of-two-windows-unreliable\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment is buggy\n*/\nfunction check() {\n\tvar k;\n\tif ( typeOf( win ) === 'undefined' ) {\n\t\treturn false;\n\t}\n\tfor ( k in win ) { // eslint-disable-line guard-for-in\n\t\ttry {\n\t\t\tif (\n\t\t\t\tindexOf( EXCLUDED_KEYS, k ) === -1 &&\n\t\t\t\thasOwnProp( win, k ) &&\n\t\t\t\twin[ k ] !== null &&\n\t\t\t\ttypeOf( win[ k ] ) === 'object'\n\t\t\t) {\n\t\t\t\tisConstructorPrototype( win[ k ] );\n\t\t\t}\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// MAIN //\n\nbool = check();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\nvar w = ( typeof window === 'undefined' ) ? void 0 : window;\n\n\n// EXPORTS //\n\nmodule.exports = w;\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// MAIN //\n\nvar bool = ( typeof window !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar hasAutomationEqualityBug = require( './has_automation_equality_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar HAS_WINDOW = require( './has_window.js' );\n\n\n// MAIN //\n\n/**\n* Wraps the test for constructor prototype equality to accommodate buggy environments (e.g., environments which throw when testing equality).\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction wrapper( value ) {\n\tif ( HAS_WINDOW === false && !hasAutomationEqualityBug ) {\n\t\treturn isConstructorPrototype( value );\n\t}\n\ttry {\n\t\treturn isConstructorPrototype( value );\n\t} catch ( error ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = wrapper;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar HAS_ENUM_PROTO_BUG = require( './has_enumerable_prototype_bug.js' );\nvar HAS_NON_ENUM_PROPS_BUG = require( './has_non_enumerable_properties_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype_wrapper.js' );\nvar NON_ENUMERABLE = require( './non_enumerable.json' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tvar skipConstructor;\n\tvar skipPrototype;\n\tvar isFcn;\n\tvar out;\n\tvar k;\n\tvar p;\n\tvar i;\n\n\tout = [];\n\tif ( isArguments( value ) ) {\n\t\t// Account for environments which treat `arguments` differently...\n\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\tout.push( i.toString() );\n\t\t}\n\t\t// Note: yes, we are precluding the `arguments` array-like object from having other enumerable properties; however, this should (1) be very rare and (2) not be encouraged (e.g., doing something like `arguments.a = 'b'`; in certain engines directly manipulating the `arguments` value results in automatic de-optimization).\n\t\treturn out;\n\t}\n\tif ( typeof value === 'string' ) {\n\t\t// Account for environments which do not treat string character indices as \"own\" properties...\n\t\tif ( value.length > 0 && !hasOwnProp( value, '0' ) ) {\n\t\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\t\tout.push( i.toString() );\n\t\t\t}\n\t\t}\n\t} else {\n\t\tisFcn = ( typeof value === 'function' );\n\t\tif ( isFcn === false && !isObjectLike( value ) ) {\n\t\t\treturn out;\n\t\t}\n\t\tskipPrototype = ( HAS_ENUM_PROTO_BUG && isFcn );\n\t}\n\tfor ( k in value ) {\n\t\tif ( !( skipPrototype && k === 'prototype' ) && hasOwnProp( value, k ) ) {\n\t\t\tout.push( String( k ) );\n\t\t}\n\t}\n\tif ( HAS_NON_ENUM_PROPS_BUG ) {\n\t\tskipConstructor = isConstructorPrototype( value );\n\t\tfor ( i = 0; i < NON_ENUMERABLE.length; i++ ) {\n\t\t\tp = NON_ENUMERABLE[ i ];\n\t\t\tif ( !( skipConstructor && p === 'constructor' ) && hasOwnProp( value, p ) ) {\n\t\t\t\tout.push( String( p ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar hasArgumentsBug = require( './has_arguments_bug.js' );\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar wrapper = require( './builtin_wrapper.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @name keys\n* @type {Function}\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nvar keys;\nif ( HAS_BUILTIN ) {\n\tif ( hasArgumentsBug() ) {\n\t\tkeys = wrapper;\n\t} else {\n\t\tkeys = builtin;\n\t}\n} else {\n\tkeys = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* Return an array of an object's own enumerable property names.\n*\n* @module @stdlib/utils-keys\n*\n* @example\n* var keys = require( '@stdlib/utils-keys' );\n*\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\n\n// MODULES //\n\nvar keys = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyNames !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyNames = Object.getOwnPropertyNames;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn propertyNames( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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\nvar keys = require( '@stdlib/utils-keys' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n* - In environments lacking support for `Object.getOwnPropertyNames()`, property descriptors are unavailable, and thus all properties can be safely assumed to be enumerable. Hence, we can defer to calling `Object.keys`, which retrieves all own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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* Return an array of an object's own enumerable and non-enumerable property names.\n*\n* @module @stdlib/utils-property-names\n*\n* @example\n* var getOwnPropertyNames = require( '@stdlib/utils-property-names' );\n*\n* var keys = getOwnPropertyNames({\n* 'foo': 'bar',\n* 'beep': 'boop'\n* });\n* // e.g., returns [ 'foo', 'beep' ]\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyDescriptor !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyDescriptor = Object.getOwnPropertyDescriptor;\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tvar desc;\n\tif ( value === null || value === void 0 ) {\n\t\treturn null;\n\t}\n\tdesc = propertyDescriptor( value, property );\n\treturn ( desc === void 0 ) ? null : desc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n* - In environments lacking `Object.getOwnPropertyDescriptor()` support, property descriptors do not exist. In non-supporting environment, if an object has a provided property, this function returns a descriptor object equivalent to that returned in a supporting environment; otherwise, the function returns `null`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tif ( hasOwnProp( value, property ) ) {\n\t\treturn {\n\t\t\t'configurable': true,\n\t\t\t'enumerable': true,\n\t\t\t'writable': true,\n\t\t\t'value': value[ property ]\n\t\t};\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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* Return a property descriptor for an object's own property.\n*\n* @module @stdlib/utils-property-descriptor\n*\n* @example\n* var getOwnPropertyDescriptor = require( '@stdlib/utils-property-descriptor' );\n*\n* var obj = {\n* 'foo': 'bar',\n* 'beep': 'boop'\n* };\n*\n* var keys = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':'bar'}\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar main = ( typeof Buffer === 'function' ) ? Buffer : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar GlobalBuffer = require( './buffer.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Buffer` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Buffer` support\n*\n* @example\n* var bool = hasNodeBufferSupport();\n* // returns \n*/\nfunction hasNodeBufferSupport() {\n\tvar bool;\n\tvar b;\n\n\tif ( typeof GlobalBuffer !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tif ( typeof GlobalBuffer.from === 'function' ) {\n\t\t\tb = GlobalBuffer.from( [ 1, 2, 3, 4 ] );\n\t\t} else {\n\t\t\tb = new GlobalBuffer( [ 1, 2, 3, 4 ] ); // Note: this is deprecated behavior starting in Node v6 (see https://nodejs.org/api/buffer.html#buffer_new_buffer_array)\n\t\t}\n\t\tbool = (\n\t\t\tisBuffer( b ) &&\n\t\t\tb[ 0 ] === 1 &&\n\t\t\tb[ 1 ] === 2 &&\n\t\t\tb[ 2 ] === 3 &&\n\t\t\tb[ 3 ] === 4\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasNodeBufferSupport;\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* Test for native `Buffer` support.\n*\n* @module @stdlib/assert-has-node-buffer-support\n*\n* @example\n* var hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\n*\n* var bool = hasNodeBufferSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasNodeBufferSupport;\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// TODO: write (browser) polyfill\n\n// MAIN //\n\n/**\n* Buffer constructor.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Buffer constructor.\n*\n* @module @stdlib/buffer-ctor\n*\n* @example\n* var ctor = require( '@stdlib/buffer-ctor' );\n*\n* var b = new ctor( [ 1, 2, 3, 4 ] );\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\nvar main = require( './buffer.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasNodeBufferSupport() ) {\n\tctor = main;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = require( 'buffer' ).Buffer; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\nvar bool = isFunction( Buffer.from );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn Buffer.from( buffer );\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn new Buffer( buffer ); // eslint-disable-line no-buffer-constructor\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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* Copy buffer data to a new `Buffer` instance.\n*\n* @module @stdlib/buffer-from-buffer\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n* var copyBuffer = require( '@stdlib/buffer-from-buffer' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = copyBuffer( b1 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFrom = require( './has_from.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar copyBuffer;\nif ( hasFrom ) {\n\tcopyBuffer = main;\n} else {\n\tcopyBuffer = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt8Array = ( typeof Int8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int8Array\n*\n* @example\n* var bool = isInt8Array( new Int8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt8Array( [] );\n* // returns false\n*/\nfunction isInt8Array( value ) {\n\treturn (\n\t\t( hasInt8Array && value instanceof Int8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt8Array;\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// MAIN //\n\nvar main = ( typeof Int8Array === 'function' ) ? Int8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt8Array = require( '@stdlib/assert-is-int8array' );\nvar INT8_MAX = require( '@stdlib/constants-int8-max' );\nvar INT8_MIN = require( '@stdlib/constants-int8-min' );\nvar GlobalInt8Array = require( './int8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int8Array` support\n*\n* @example\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\nfunction hasInt8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt8Array( [ 1, 3.14, -3.14, INT8_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT8_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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* Minimum signed 8-bit integer.\n*\n* @module @stdlib/constants-int8-min\n* @type {integer32}\n*\n* @example\n* var INT8_MIN = require( '@stdlib/constants-int8-min' );\n* // returns -128\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 8-bit integer.\n*\n* ## Notes\n*\n* The number is given by\n*\n* ```tex\n* -(2^{7})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -128\n*/\nvar INT8_MIN = -128|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT8_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int8\n*\n* @example\n* var ctor = require( '@stdlib/array-int8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\nvar builtin = require( './int8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int8Array === 'function' ) ? Int8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int8Array` support.\n*\n* @module @stdlib/assert-has-int8array-support\n*\n* @example\n* var hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\n*\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8Array = ( typeof Uint8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8Array\n*\n* @example\n* var bool = isUint8Array( new Uint8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8Array( [] );\n* // returns false\n*/\nfunction isUint8Array( value ) {\n\treturn (\n\t\t( hasUint8Array && value instanceof Uint8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8Array;\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// MAIN //\n\nvar main = ( typeof Uint8Array === 'function' ) ? Uint8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8Array = require( '@stdlib/assert-is-uint8array' );\nvar UINT8_MAX = require( '@stdlib/constants-uint8-max' );\nvar GlobalUint8Array = require( './uint8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8Array` support\n*\n* @example\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\nfunction hasUint8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT8_MAX+1, UINT8_MAX+2 ];\n\t\tarr = new GlobalUint8Array( arr );\n\t\tbool = (\n\t\t\tisUint8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT8_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint8\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\nvar builtin = require( './uint8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8Array === 'function' ) ? Uint8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8Array` support.\n*\n* @module @stdlib/assert-has-uint8array-support\n*\n* @example\n* var hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\n*\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8ClampedArray = ( typeof Uint8ClampedArray === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8ClampedArray.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8ClampedArray\n*\n* @example\n* var bool = isUint8ClampedArray( new Uint8ClampedArray( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8ClampedArray( [] );\n* // returns false\n*/\nfunction isUint8ClampedArray( value ) {\n\treturn (\n\t\t( hasUint8ClampedArray && value instanceof Uint8ClampedArray ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8ClampedArray]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8ClampedArray;\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// MAIN //\n\nvar main = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8ClampedArray = require( '@stdlib/assert-is-uint8clampedarray' );\nvar GlobalUint8ClampedArray = require( './uint8clampedarray.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8ClampedArray` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8ClampedArray` support\n*\n* @example\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\nfunction hasUint8ClampedArraySupport() { // eslint-disable-line id-length\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8ClampedArray !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalUint8ClampedArray( [ -1, 0, 1, 3.14, 4.99, 255, 256 ] );\n\t\tbool = (\n\t\t\tisUint8ClampedArray( arr ) &&\n\t\t\tarr[ 0 ] === 0 && // clamped\n\t\t\tarr[ 1 ] === 0 &&\n\t\t\tarr[ 2 ] === 1 &&\n\t\t\tarr[ 3 ] === 3 && // round to nearest\n\t\t\tarr[ 4 ] === 5 && // round to nearest\n\t\t\tarr[ 5 ] === 255 &&\n\t\t\tarr[ 6 ] === 255 // clamped\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @module @stdlib/array-uint8c\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8c' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' ); // eslint-disable-line id-length\nvar builtin = require( './uint8clampedarray.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ClampedArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8ClampedArray` support.\n*\n* @module @stdlib/assert-has-uint8clampedarray-support\n*\n* @example\n* var hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' );\n*\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt16Array = ( typeof Int16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int16Array\n*\n* @example\n* var bool = isInt16Array( new Int16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt16Array( [] );\n* // returns false\n*/\nfunction isInt16Array( value ) {\n\treturn (\n\t\t( hasInt16Array && value instanceof Int16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt16Array;\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// MAIN //\n\nvar main = ( typeof Int16Array === 'function' ) ? Int16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt16Array = require( '@stdlib/assert-is-int16array' );\nvar INT16_MAX = require( '@stdlib/constants-int16-max' );\nvar INT16_MIN = require( '@stdlib/constants-int16-min' );\nvar GlobalInt16Array = require( './int16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int16Array` support\n*\n* @example\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\nfunction hasInt16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt16Array( [ 1, 3.14, -3.14, INT16_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT16_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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* Minimum signed 16-bit integer.\n*\n* @module @stdlib/constants-int16-min\n* @type {integer32}\n*\n* @example\n* var INT16_MIN = require( '@stdlib/constants-int16-min' );\n* // returns -32768\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 16-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{15})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 1000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -32768\n*/\nvar INT16_MIN = -32768|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT16_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int16\n*\n* @example\n* var ctor = require( '@stdlib/array-int16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\nvar builtin = require( './int16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int16Array === 'function' ) ? Int16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int16Array` support.\n*\n* @module @stdlib/assert-has-int16array-support\n*\n* @example\n* var hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\n*\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint16Array = ( typeof Uint16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint16Array\n*\n* @example\n* var bool = isUint16Array( new Uint16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint16Array( [] );\n* // returns false\n*/\nfunction isUint16Array( value ) {\n\treturn (\n\t\t( hasUint16Array && value instanceof Uint16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint16Array;\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// MAIN //\n\nvar main = ( typeof Uint16Array === 'function' ) ? Uint16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint16Array = require( '@stdlib/assert-is-uint16array' );\nvar UINT16_MAX = require( '@stdlib/constants-uint16-max' );\nvar GlobalUint16Array = require( './uint16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint16Array` support\n*\n* @example\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\nfunction hasUint16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT16_MAX+1, UINT16_MAX+2 ];\n\t\tarr = new GlobalUint16Array( arr );\n\t\tbool = (\n\t\t\tisUint16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT16_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 16-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint16\n*\n* @example\n* var ctor = require( '@stdlib/array-uint16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\nvar builtin = require( './uint16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint16Array === 'function' ) ? Uint16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint16Array` support.\n*\n* @module @stdlib/assert-has-uint16array-support\n*\n* @example\n* var hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\n*\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt32Array = ( typeof Int32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int32Array\n*\n* @example\n* var bool = isInt32Array( new Int32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt32Array( [] );\n* // returns false\n*/\nfunction isInt32Array( value ) {\n\treturn (\n\t\t( hasInt32Array && value instanceof Int32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt32Array;\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// MAIN //\n\nvar main = ( typeof Int32Array === 'function' ) ? Int32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt32Array = require( '@stdlib/assert-is-int32array' );\nvar INT32_MAX = require( '@stdlib/constants-int32-max' );\nvar INT32_MIN = require( '@stdlib/constants-int32-min' );\nvar GlobalInt32Array = require( './int32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int32Array` support\n*\n* @example\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\nfunction hasInt32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt32Array( [ 1, 3.14, -3.14, INT32_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT32_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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* Minimum signed 32-bit integer.\n*\n* @module @stdlib/constants-int32-min\n* @type {integer32}\n*\n* @example\n* var INT32_MIN = require( '@stdlib/constants-int32-min' );\n* // returns -2147483648\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 32-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{31})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -2147483648\n*/\nvar INT32_MIN = -2147483648|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT32_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int32\n*\n* @example\n* var ctor = require( '@stdlib/array-int32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\nvar builtin = require( './int32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int32Array === 'function' ) ? Int32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int32Array` support.\n*\n* @module @stdlib/assert-has-int32array-support\n*\n* @example\n* var hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\n*\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint32Array = ( typeof Uint32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint32Array\n*\n* @example\n* var bool = isUint32Array( new Uint32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint32Array( [] );\n* // returns false\n*/\nfunction isUint32Array( value ) {\n\treturn (\n\t\t( hasUint32Array && value instanceof Uint32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint32Array;\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// MAIN //\n\nvar main = ( typeof Uint32Array === 'function' ) ? Uint32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint32Array = require( '@stdlib/assert-is-uint32array' );\nvar UINT32_MAX = require( '@stdlib/constants-uint32-max' );\nvar GlobalUint32Array = require( './uint32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint32Array` support\n*\n* @example\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\nfunction hasUint32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT32_MAX+1, UINT32_MAX+2 ];\n\t\tarr = new GlobalUint32Array( arr );\n\t\tbool = (\n\t\t\tisUint32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT32_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 32-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint32\n*\n* @example\n* var ctor = require( '@stdlib/array-uint32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\nvar builtin = require( './uint32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint32Array === 'function' ) ? Uint32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint32Array` support.\n*\n* @module @stdlib/assert-has-uint32array-support\n*\n* @example\n* var hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\n*\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat32Array = ( typeof Float32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float32Array\n*\n* @example\n* var bool = isFloat32Array( new Float32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat32Array( [] );\n* // returns false\n*/\nfunction isFloat32Array( value ) {\n\treturn (\n\t\t( hasFloat32Array && value instanceof Float32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat32Array;\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// MAIN //\n\nvar main = ( typeof Float32Array === 'function' ) ? Float32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat32Array = require( '@stdlib/assert-is-float32array' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar GlobalFloat32Array = require( './float32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float32Array` support\n*\n* @example\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\nfunction hasFloat32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat32Array( [ 1.0, 3.14, -3.14, 5.0e40 ] );\n\t\tbool = (\n\t\t\tisFloat32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.140000104904175 &&\n\t\t\tarr[ 2 ] === -3.140000104904175 &&\n\t\t\tarr[ 3 ] === PINF\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of single-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float32\n*\n* @example\n* var ctor = require( '@stdlib/array-float32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\nvar builtin = require( './float32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float32Array === 'function' ) ? Float32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float32Array` support.\n*\n* @module @stdlib/assert-has-float32array-support\n*\n* @example\n* var hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\n*\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat64Array = ( typeof Float64Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float64Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float64Array\n*\n* @example\n* var bool = isFloat64Array( new Float64Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat64Array( [] );\n* // returns false\n*/\nfunction isFloat64Array( value ) {\n\treturn (\n\t\t( hasFloat64Array && value instanceof Float64Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float64Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat64Array;\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// MAIN //\n\nvar main = ( typeof Float64Array === 'function' ) ? Float64Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat64Array = require( '@stdlib/assert-is-float64array' );\nvar GlobalFloat64Array = require( './float64array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float64Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float64Array` support\n*\n* @example\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\nfunction hasFloat64ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat64Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat64Array( [ 1.0, 3.14, -3.14, NaN ] );\n\t\tbool = (\n\t\t\tisFloat64Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.14 &&\n\t\t\tarr[ 2 ] === -3.14 &&\n\t\t\tarr[ 3 ] !== arr[ 3 ]\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of double-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float64\n*\n* @example\n* var ctor = require( '@stdlib/array-float64' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\nvar builtin = require( './float64array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat64ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float64Array === 'function' ) ? Float64Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float64Array` support.\n*\n* @module @stdlib/assert-has-float64array-support\n*\n* @example\n* var hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\n*\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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\nvar Int8Array = require( '@stdlib/array-int8' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar Uint8ClampedArray = require( '@stdlib/array-uint8c' );\nvar Int16Array = require( '@stdlib/array-int16' );\nvar Uint16Array = require( '@stdlib/array-uint16' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar Uint32Array = require( '@stdlib/array-uint32' );\nvar Float32Array = require( '@stdlib/array-float32' );\nvar Float64Array = require( '@stdlib/array-float64' );\n\n\n// VARIABLES //\n\nvar hash;\n\n\n// FUNCTIONS //\n\n/**\n* Copies an `Int8Array`.\n*\n* @private\n* @param {Int8Array} arr - array to copy\n* @returns {Int8Array} new array\n*/\nfunction int8array( arr ) {\n\treturn new Int8Array( arr );\n}\n\n/**\n* Copies a `Uint8Array`.\n*\n* @private\n* @param {Uint8Array} arr - array to copy\n* @returns {Uint8Array} new array\n*/\nfunction uint8array( arr ) {\n\treturn new Uint8Array( arr );\n}\n\n/**\n* Copies a `Uint8ClampedArray`.\n*\n* @private\n* @param {Uint8ClampedArray} arr - array to copy\n* @returns {Uint8ClampedArray} new array\n*/\nfunction uint8clampedarray( arr ) {\n\treturn new Uint8ClampedArray( arr );\n}\n\n/**\n* Copies an `Int16Array`.\n*\n* @private\n* @param {Int16Array} arr - array to copy\n* @returns {Int16Array} new array\n*/\nfunction int16array( arr ) {\n\treturn new Int16Array( arr );\n}\n\n/**\n* Copies a `Uint16Array`.\n*\n* @private\n* @param {Uint16Array} arr - array to copy\n* @returns {Uint16Array} new array\n*/\nfunction uint16array( arr ) {\n\treturn new Uint16Array( arr );\n}\n\n/**\n* Copies an `Int32Array`.\n*\n* @private\n* @param {Int32Array} arr - array to copy\n* @returns {Int32Array} new array\n*/\nfunction int32array( arr ) {\n\treturn new Int32Array( arr );\n}\n\n/**\n* Copies a `Uint32Array`.\n*\n* @private\n* @param {Uint32Array} arr - array to copy\n* @returns {Uint32Array} new array\n*/\nfunction uint32array( arr ) {\n\treturn new Uint32Array( arr );\n}\n\n/**\n* Copies a `Float32Array`.\n*\n* @private\n* @param {Float32Array} arr - array to copy\n* @returns {Float32Array} new array\n*/\nfunction float32array( arr ) {\n\treturn new Float32Array( arr );\n}\n\n/**\n* Copies a `Float64Array`.\n*\n* @private\n* @param {Float64Array} arr - array to copy\n* @returns {Float64Array} new array\n*/\nfunction float64array( arr ) {\n\treturn new Float64Array( arr );\n}\n\n/**\n* Returns a hash of functions for copying typed arrays.\n*\n* @private\n* @returns {Object} function hash\n*/\nfunction typedarrays() {\n\tvar out = {\n\t\t'int8array': int8array,\n\t\t'uint8array': uint8array,\n\t\t'uint8clampedarray': uint8clampedarray,\n\t\t'int16array': int16array,\n\t\t'uint16array': uint16array,\n\t\t'int32array': int32array,\n\t\t'uint32array': uint32array,\n\t\t'float32array': float32array,\n\t\t'float64array': float64array\n\t};\n\treturn out;\n}\n\n\n// MAIN //\n\nhash = typedarrays();\n\n\n// EXPORTS //\n\nmodule.exports = hash;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar regexp = require( '@stdlib/utils-regexp-from-string' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar propertyNames = require( '@stdlib/utils-property-names' );\nvar propertyDescriptor = require( '@stdlib/utils-property-descriptor' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar defineProperty = require( '@stdlib/utils-define-property' );\nvar copyBuffer = require( '@stdlib/buffer-from-buffer' );\nvar typedArrays = require( './typed_arrays.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Clones a class instance.\n*\n* ## Notes\n*\n* - This should **only** be used for simple cases. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This approach should be considered **fragile**.\n* - The function is greedy, disregarding the notion of a `level`. Instead, the function deep copies all properties, as we assume the concept of `level` applies only to the class instance reference but not to its internal state. This prevents, in theory, two instances from sharing state.\n*\n*\n* @private\n* @param {Object} val - class instance\n* @returns {Object} new instance\n*/\nfunction cloneInstance( val ) {\n\tvar cache;\n\tvar names;\n\tvar name;\n\tvar refs;\n\tvar desc;\n\tvar tmp;\n\tvar ref;\n\tvar i;\n\n\tcache = [];\n\trefs = [];\n\n\tref = Object.create( getPrototypeOf( val ) );\n\tcache.push( val );\n\trefs.push( ref );\n\n\tnames = propertyNames( val );\n\tfor ( i = 0; i < names.length; i++ ) {\n\t\tname = names[ i ];\n\t\tdesc = propertyDescriptor( val, name );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( val[name] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( val[name], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( ref, name, desc );\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( ref );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( ref );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( ref );\n\t}\n\treturn ref;\n}\n\n/**\n* Copies an error object.\n*\n* @private\n* @param {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error - error to copy\n* @returns {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error copy\n*\n* @example\n* var err1 = new TypeError( 'beep' );\n*\n* var err2 = copyError( err1 );\n* // returns \n*/\nfunction copyError( error ) {\n\tvar cache = [];\n\tvar refs = [];\n\tvar keys;\n\tvar desc;\n\tvar tmp;\n\tvar key;\n\tvar err;\n\tvar i;\n\n\t// Create a new error...\n\terr = new error.constructor( error.message );\n\n\tcache.push( error );\n\trefs.push( err );\n\n\t// If a `stack` property is present, copy it over...\n\tif ( error.stack ) {\n\t\terr.stack = error.stack;\n\t}\n\t// Node.js specific (system errors)...\n\tif ( error.code ) {\n\t\terr.code = error.code;\n\t}\n\tif ( error.errno ) {\n\t\terr.errno = error.errno;\n\t}\n\tif ( error.syscall ) {\n\t\terr.syscall = error.syscall;\n\t}\n\t// Any enumerable properties...\n\tkeys = objectKeys( error );\n\tfor ( i = 0; i < keys.length; i++ ) {\n\t\tkey = keys[ i ];\n\t\tdesc = propertyDescriptor( error, key );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( error[ key ] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( error[ key ], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( err, key, desc );\n\t}\n\treturn err;\n}\n\n\n// MAIN //\n\n/**\n* Recursively performs a deep copy of an input object.\n*\n* @private\n* @param {*} val - value to copy\n* @param {(Array|Object)} copy - copy\n* @param {Array} cache - an array of visited objects\n* @param {Array} refs - an array of object references\n* @param {NonNegativeInteger} level - copy depth\n* @returns {*} deep copy\n*/\nfunction deepCopy( val, copy, cache, refs, level ) {\n\tvar parent;\n\tvar keys;\n\tvar name;\n\tvar desc;\n\tvar ctor;\n\tvar key;\n\tvar ref;\n\tvar x;\n\tvar i;\n\tvar j;\n\n\tlevel -= 1;\n\n\t// Primitives and functions...\n\tif (\n\t\ttypeof val !== 'object' ||\n\t\tval === null\n\t) {\n\t\treturn val;\n\t}\n\tif ( isBuffer( val ) ) {\n\t\treturn copyBuffer( val );\n\t}\n\tif ( isError( val ) ) {\n\t\treturn copyError( val );\n\t}\n\t// Objects...\n\tname = typeOf( val );\n\n\tif ( name === 'date' ) {\n\t\treturn new Date( +val );\n\t}\n\tif ( name === 'regexp' ) {\n\t\treturn regexp( val.toString() );\n\t}\n\tif ( name === 'set' ) {\n\t\treturn new Set( val );\n\t}\n\tif ( name === 'map' ) {\n\t\treturn new Map( val );\n\t}\n\tif (\n\t\tname === 'string' ||\n\t\tname === 'boolean' ||\n\t\tname === 'number'\n\t) {\n\t\t// If provided an `Object`, return an equivalent primitive!\n\t\treturn val.valueOf();\n\t}\n\tctor = typedArrays[ name ];\n\tif ( ctor ) {\n\t\treturn ctor( val );\n\t}\n\t// Class instances...\n\tif (\n\t\tname !== 'array' &&\n\t\tname !== 'object'\n\t) {\n\t\t// Cloning requires ES5 or higher...\n\t\tif ( typeof Object.freeze === 'function' ) {\n\t\t\treturn cloneInstance( val );\n\t\t}\n\t\treturn {};\n\t}\n\t// Arrays and plain objects...\n\tkeys = objectKeys( val );\n\tif ( level > 0 ) {\n\t\tparent = name;\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tx = val[ key ];\n\n\t\t\t// Primitive, Buffer, special class instance...\n\t\t\tname = typeOf( x );\n\t\t\tif (\n\t\t\t\ttypeof x !== 'object' ||\n\t\t\t\tx === null ||\n\t\t\t\t(\n\t\t\t\t\tname !== 'array' &&\n\t\t\t\t\tname !== 'object'\n\t\t\t\t) ||\n\t\t\t\tisBuffer( x )\n\t\t\t) {\n\t\t\t\tif ( parent === 'object' ) {\n\t\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\t\tdesc.value = deepCopy( x );\n\t\t\t\t\t}\n\t\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t\t} else {\n\t\t\t\t\tcopy[ key ] = deepCopy( x );\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Circular reference...\n\t\t\ti = indexOf( cache, x );\n\t\t\tif ( i !== -1 ) {\n\t\t\t\tcopy[ key ] = refs[ i ];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Plain array or object...\n\t\t\tref = ( isArray( x ) ) ? new Array( x.length ) : {};\n\t\t\tcache.push( x );\n\t\t\trefs.push( ref );\n\t\t\tif ( parent === 'array' ) {\n\t\t\t\tcopy[ key ] = deepCopy( x, ref, cache, refs, level );\n\t\t\t} else {\n\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\tdesc.value = deepCopy( x, ref, cache, refs, level );\n\t\t\t\t}\n\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t}\n\t\t}\n\t} else if ( name === 'array' ) {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tcopy[ key ] = val[ key ];\n\t\t}\n\t} else {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\tdefineProperty( copy, key, desc );\n\t\t}\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( copy );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( copy );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( copy );\n\t}\n\treturn copy;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepCopy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar deepCopy = require( './deep_copy.js' );\n\n\n// MAIN //\n\n/**\n* Copies or deep clones a value to an arbitrary depth.\n*\n* @param {*} value - value to copy\n* @param {NonNegativeInteger} [level=+infinity] - copy depth\n* @throws {TypeError} `level` must be a nonnegative integer\n* @returns {*} value copy\n*\n* @example\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\nfunction copy( value, level ) {\n\tvar out;\n\tif ( arguments.length > 1 ) {\n\t\tif ( !isNonNegativeInteger( level ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `level` must be a nonnegative integer. Value: `' + level + '`.' );\n\t\t}\n\t\tif ( level === 0 ) {\n\t\t\treturn value;\n\t\t}\n\t} else {\n\t\tlevel = PINF;\n\t}\n\tout = ( isArray( value ) ) ? new Array( value.length ) : {};\n\treturn deepCopy( value, out, [value], [out], level );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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* Copy or deep clone a value to an arbitrary depth.\n*\n* @module @stdlib/utils-copy\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ {'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\n\n// MODULES //\n\nvar copy = require( './copy.js' );\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an object; e.g., `{}`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an object\n*\n* @example\n* var bool = isObject( {} );\n* // returns true\n*\n* @example\n* var bool = isObject( null );\n* // returns false\n*/\nfunction isObject( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t!isArray( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObject;\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\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar objectPrototype = Object.prototype;\n\n\n// FUNCTIONS //\n\n/**\n* Tests that an object only has own properties.\n*\n* @private\n* @param {Object} obj - value to test\n* @returns {boolean} boolean indicating if an object only has own properties\n*/\nfunction ownProps( obj ) {\n\tvar key;\n\n\t// NOTE: possibility of perf boost if key enumeration order is known (see http://stackoverflow.com/questions/18531624/isplainobject-thing).\n\tfor ( key in obj ) {\n\t\tif ( !hasOwnProp( obj, key ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n\n// MAIN //\n\n/**\n* Tests if a value is a plain object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a plain object\n*\n* @example\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* @example\n* var bool = isPlainObject( null );\n* // returns false\n*/\nfunction isPlainObject( value ) {\n\tvar proto;\n\n\t// Screen for obvious non-objects...\n\tif ( !isObject( value ) ) {\n\t\treturn false;\n\t}\n\t// Objects with no prototype (e.g., `Object.create( null )`) are plain...\n\tproto = getPrototypeOf( value );\n\tif ( !proto ) {\n\t\treturn true;\n\t}\n\t// Objects having a prototype are plain if and only if they are constructed with a global `Object` function and the prototype points to the prototype of a plain object...\n\treturn (\n\t\t// Cannot have own `constructor` property:\n\t\t!hasOwnProp( value, 'constructor' ) &&\n\n\t\t// Prototype `constructor` property must be a function (see also https://bugs.jquery.com/ticket/9897 and http://stackoverflow.com/questions/18531624/isplainobject-thing):\n\t\thasOwnProp( proto, 'constructor' ) &&\n\t\tisFunction( proto.constructor ) &&\n\t\tnativeClass( proto.constructor ) === '[object Function]' &&\n\n\t\t// Test for object-specific method:\n\t\thasOwnProp( proto, 'isPrototypeOf' ) &&\n\t\tisFunction( proto.isPrototypeOf ) &&\n\n\t\t(\n\t\t\t// Test if the prototype matches the global `Object` prototype (same realm):\n\t\t\tproto === objectPrototype ||\n\n\t\t\t// Test that all properties are own properties (cross-realm; *most* likely a plain object):\n\t\t\townProps( value )\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - options to validate\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {(Error|null)} error object or null\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );\n\t}\n\tif ( hasOwnProp( options, 'url' ) ) {\n\t\topts.url = options.url;\n\t\tif ( !isString( opts.url ) ) {\n\t\t\treturn new TypeError( 'invalid option. `url` option must be a string primitive. Option: `' + opts.url + '`.' );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'message' ) ) {\n\t\topts.message = options.message;\n\t\tif ( !isString( opts.message ) ) {\n\t\t\treturn new TypeError( 'invalid option. `message` option must be a string primitive. Option: `' + opts.message + '`.' );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\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* Test if a value is a plain object.\n*\n* @module @stdlib/assert-is-plain-object\n*\n* @example\n* var isPlainObject = require( '@stdlib/assert-is-plain-object' );\n*\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* bool = isPlainObject( null );\n* // returns false\n*/\n\n// MODULES //\n\nvar isPlainObject = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar replace = require( '@stdlib/string-replace' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Returns a function which formats an error message for production.\n*\n* @param {Options} options - function options\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {Function} error formatting function\n*\n* @example\n* var opts = {\n* 'url': 'https://stdlib.io/error-decoder.html'\n* };\n*\n* var fcn = factory( opts );\n* // returns \n*/\nfunction factory( options ) {\n\tvar opts;\n\tvar err;\n\topts = copy( defaults );\n\terr = validate( opts, options );\n\tif ( err ) {\n\t\tthrow err;\n\t}\n\treturn formatProdErrorMessage;\n\n\t/**\n\t* Formats an error message for production.\n\t*\n\t* @private\n\t* @param {string} code - error code\n\t* @param {*} ...args - error message arguments\n\t* @returns {string} formatted error message\n\t*/\n\tfunction formatProdErrorMessage() {\n\t\tvar code = arguments[ 0 ];\n\t\tvar url = opts.url + '?code='+code;\n\t\tvar msg;\n\t\tvar i;\n\t\tfor ( i = 1; i < arguments.length; i++ ) {\n\t\t\turl += '&arg[]=' + encodeURIComponent( arguments[ i ] );\n\t\t}\n\t\tmsg = replace( opts.message, '{{url}}', url );\n\t\tmsg = replace( msg, '{{code}}', code );\n\t\treturn msg;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Format an error message for production.\n*\n* @module @stdlib/error-tools-fmtprodmsg\n*\n* @example\n* var formatProdErrorMessage = require( '@stdlib/error-tools-fmtprodmsg' );\n*\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar formatProdErrorMessage = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( formatProdErrorMessage, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @name formatProdErrorMessage\n* @type {Function}\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\nvar formatProdErrorMessage = factory( defaults );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["defineProperty","Object","has_define_property_support","err","builtin","objectProtoype","prototype","toStr","toString","defineGetter","__defineGetter__","defineSetter","__defineSetter__","lookupGetter","__lookupGetter__","lookupSetter","__lookupSetter__","polyfill","obj","prop","descriptor","hasValue","hasGet","hasSet","call","TypeError","__proto__","value","Error","get","set","require$$1","require$$2","lib","require$$0","main","configurable","enumerable","writable","primitive","FLG","Symbol","hasSymbols","toStringTag","tostring","native_class","v","has","hasOwnProperty","property","toStrTag","hasOwnProp","isOwn","tag","out","valueOf","String","nativeClass","test","object","isPrimitive","isObject","setReadOnly","isString","require$$3","RE_CHARS","str","s","i","length","replace","substring","re","Boolean","isBoolean","codegen","Function","self_1","self","window_1","window","global","module","exports","getThis","Self","Win","Global","arguments","root","nodeList","document","childNodes","typedarray","Int8Array","RE","check_1","reFunctionName","Array","isArray","isObjectLike","predicate","len","arrayfun","_isBuffer","constructor","isBuffer","REGEXP","match","name","ctor","slice","exec","ctorName","typeOf","type","toLowerCase","RegExp","rescape","isFunction","isRegExp","search","newval","Number","isNumber","POSITIVE_INFINITY","NEGATIVE_INFINITY","floor","Math","x","PINF","NINF","isInt","integer","isInteger","isNonNegativeInteger","getProto","getPrototypeOf","proto","reRegExp","isNan","isnan","isCollection","index_of","arr","searchElement","fromIndex","keys","has_arguments_bug","has_builtin","bool","isArguments","bool$8","detect","detect_1","native","propertyIsEnumerable","bool$7","isEnum","hasStringEnumBug","isEnumerableProperty","require$$4","builtin_wrapper","has_enumerable_prototype_bug","has_non_enumerable_properties_bug","is_constructor_prototype","w","indexOf","isConstructorPrototype","EXCLUDED_KEYS","win","bool$4","k","check","hasAutomationEqualityBug","HAS_WINDOW","HAS_ENUM_PROTO_BUG","HAS_NON_ENUM_PROPS_BUG","error","NON_ENUMERABLE","wrapper","skipConstructor","skipPrototype","isFcn","p","push","getOwnPropertyNames","propertyNames","getOwnPropertyDescriptor","propertyDescriptor","desc","Buffer","GlobalBuffer","b","from","buffer","hasInt8Array","isInt8Array","GlobalInt8Array","INT8_MAX","hasUint8Array","Uint8Array","isUint8Array","GlobalUint8Array","UINT8_MAX","hasUint8ClampedArray","Uint8ClampedArray","isUint8ClampedArray","GlobalUint8ClampedArray","hasInt16Array","Int16Array","isInt16Array","GlobalInt16Array","INT16_MAX","hasUint16Array","Uint16Array","isUint16Array","GlobalUint16Array","UINT16_MAX","hasInt32Array","Int32Array","isInt32Array","GlobalInt32Array","INT32_MAX","hasUint32Array","Uint32Array","isUint32Array","GlobalUint32Array","UINT32_MAX","hasFloat32Array","Float32Array","isFloat32Array","GlobalFloat32Array","hasFloat64Array","Float64Array","isFloat64Array","GlobalFloat64Array","NaN","require$$5","require$$6","require$$7","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","isError","regexp","objectKeys","require$$8","require$$9","require$$10","require$$11","copyBuffer","require$$12","typedArrays","deepCopy","val","copy","cache","refs","level","parent","key","ref","j","tmp","message","stack","code","errno","syscall","copyError","Date","Set","Map","freeze","names","create","isExtensible","preventExtensions","isSealed","seal","isFrozen","cloneInstance","copy_1","objectPrototype","isPrototypeOf","ownProps","validate","opts","options","url","defaults","factory_1","msg","encodeURIComponent","formatProdErrorMessage","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","RangeError","format"],"mappings":";6kBAsBA,ICAIA,EDA0C,mBAA1BC,OAAOD,eAAkCC,OAAOD,eAAiB,KC4BrF,IAAAE,EAbA,WAEC,IAEC,OADAF,EAAgB,GAAI,IAAK,KAClB,EACN,MAAQG,GACT,OAAO,ICiBTC,EALqBH,OAAOD,eC/BxBK,EAAiBJ,OAAOK,UACxBC,EAAQF,EAAeG,SACvBC,EAAeJ,EAAeK,iBAC9BC,EAAeN,EAAeO,iBAC9BC,EAAeR,EAAeS,iBAC9BC,EAAeV,EAAeW,iBAuFlC,IAAAC,EAnDA,SAAyBC,EAAKC,EAAMC,GACnC,IAAId,EACAe,EACAC,EACAC,EAEJ,GAAoB,iBAARL,GAA4B,OAARA,GAAsC,mBAAtBX,EAAMiB,KAAMN,GAC3D,MAAM,IAAIO,UAAW,+DAAiEP,EAAM,MAE7F,GAA2B,iBAAfE,GAA0C,OAAfA,GAAoD,mBAA7Bb,EAAMiB,KAAMJ,GACzE,MAAM,IAAIK,UAAW,oEAAsEL,EAAa,MAyBzG,IAvBAC,EAAa,UAAWD,KAGtBP,EAAaW,KAAMN,EAAKC,IACxBJ,EAAaS,KAAMN,EAAKC,IAGxBb,EAAYY,EAAIQ,UAChBR,EAAIQ,UAAYrB,SAGTa,EAAKC,GACZD,EAAKC,GAASC,EAAWO,MAGzBT,EAAIQ,UAAYpB,GAEhBY,EAAKC,GAASC,EAAWO,OAG3BL,EAAW,QAASF,EACpBG,EAAW,QAASH,EAEfC,IAAcC,GAAUC,GAC5B,MAAM,IAAIK,MAAO,wHASlB,OANKN,GAAUb,GACdA,EAAae,KAAMN,EAAKC,EAAMC,EAAWS,KAErCN,GAAUZ,GACdA,EAAaa,KAAMN,EAAKC,EAAMC,EAAWU,KAEnCZ,GCrEJd,EAAU2B,EACVd,EAAWe,EAefC,EAjB+BC,IASb9B,EAEAa,EC7BdjB,EAAiBkC,EAmCrB,IAAAC,EAZA,SAAmCjB,EAAKC,EAAMQ,GAC7C3B,EAAgBkB,EAAKC,EAAM,CAC1BiB,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,KCJXM,EAL+BC,ECA/B,IAAAK,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCMjB,ICdIa,EDIJ,WACC,MACmB,mBAAXC,QACoB,iBAApBA,OAAQ,OCPPC,GAqBV,ICTAT,EDEA,WACC,OAASO,GAAqC,iBAAvBC,OAAOE,aEf/BC,EALY3C,OAAOK,UAAUE,SCAzBD,EAAQ2B,EAiCZ,IAAAW,EAPA,SAAsBC,GACrB,OAAOvC,EAAMiB,KAAMsB,IC3BhBC,EAAM9C,OAAOK,UAAU0C,eAyC3B,ICjBAf,EDIA,SAAqBN,EAAOsB,GAC3B,OACCtB,SAKMoB,EAAIvB,KAAMG,EAAOsB,IEnCrBC,EAA+B,mBAAXT,OAA0BA,OAAOE,YAAc,GCAnEQ,EAAajB,EACbS,EDIaO,ECHb3C,EAAQyB,EAwDZ,ICpCI5B,EAAU2B,EACVd,EDKJ,SAAsB6B,GACrB,IAAIM,EACAC,EACAC,EAEJ,GAAKR,QACJ,OAAOvC,EAAMiB,KAAMsB,GAEpBO,EAAMP,EAAGH,GACTS,EAAQD,EAAYL,EAAGH,GAGvB,IACCG,EAAGH,QAAgB,EAClB,MAAQxC,GACT,OAAOI,EAAMiB,KAAMsB,GASpB,OAPAQ,EAAM/C,EAAMiB,KAAMsB,GAEbM,EACJN,EAAGH,GAAgBU,SAEZP,EAAGH,GAEJW,GCdRrB,EAjBqBC,IASNjB,EAEAb,EChCXmD,ECDUC,OAAOlD,UAAUiD,QDyB/B,IEvBIE,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADA4B,EAAQ/B,KAAMG,IACP,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB6B,SAGjBhB,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,EAAW9B,EA0Bf,ICSI+B,EAAc5B,EACd6B,EDjBJ,SAAmBpC,GAClB,OAASiC,EAAajC,IAAWkC,EAAUlC,ICkBxCkC,EAAWG,EAKfF,EAAaC,EAAU,cANL/B,GAOlB8B,EAAaC,EAAU,WAAYF,GAKnC,IAAA5B,EAAiB8B,EClDbA,EAAW7B,EAAsC0B,YAKjDK,EAAW,yBAqDf,ICzCAhC,EDIA,SAAkBiC,GACjB,IACIC,EACAC,EAEJ,IAAML,EAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAGrG,GAAkB,MAAbA,EAAK,GAGT,IAAME,EADAF,EAAIG,OACI,EAAGD,GAAK,GACH,MAAbF,EAAKE,GADcA,KAO1B,YAAW,IAANA,GAAgBA,GAAK,EAClBF,EAAII,QAASL,EAAU,SAM/BE,GAHAA,EAAID,EAAIK,UAAW,EAAGH,IAGhBE,QAASL,EAAU,QAGzBC,EAAMA,EAAK,GAAMC,EAAID,EAAIK,UAAWH,KE/CrCI,EALS,ICyBT,IAAAjC,EAPA,SAAoBZ,GACnB,MAA0B,kBAAVA,GCjBbnB,ECDWiE,QAAQnE,UAAUE,SDyBjC,IEvBIiD,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADAnB,EAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAoBhC,GACnB,MAAsB,iBAAVA,IACNA,aAAiB8C,UAGjBjC,EACGkB,EAAM/B,GAEoB,qBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,GAAW9B,EAkCf,ICAI+B,GAAc5B,EACdwC,GDRJ,SAAoB/C,GACnB,OAASiC,EAAajC,IAAWkC,GAAUlC,ICSxCkC,GAAWG,EAKfF,GAAaY,GAAW,cANN1C,GAOlB8B,GAAaY,GAAW,WAAYb,IAKpC,IAAA5B,GAAiByC,GCpCjB,IAAAC,GAPA,WACC,OAAO,IAAIC,SAAU,eAAd,ICFRC,GAL4B,iBAATC,KAAsBA,KAAO,KCKhDC,GAL8B,iBAAXC,OAAwBA,OAAS,6GCAhD9D,GAA0B,iBAAX+D,GAAwBA,GAAS,KAKpDC,OAAOC,QAAUjE,OCLbwD,GAAYxC,GAAuC0B,YACnDwB,GAAUrD,GACVsD,GAAOrD,GACPsD,GAAMtB,GACNuB,sCAkDJ,IAAApD,GA7BA,SAAoBwC,GACnB,GAAKa,UAAUnB,OAAS,CACvB,IAAMK,GAAWC,GAChB,MAAM,IAAIlD,UAAW,+DAA+DkD,EAAQ,MAE7F,GAAKA,EACJ,OAAOS,KAKT,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,MAAM,IAAI3D,MAAO,uDC3Cd6D,GCOYvD,KDNZwD,GAAWD,GAAKE,UAAYF,GAAKE,SAASC,WER1CC,GAAaC,UCEbC,GAAK7D,EACLwD,GHUaA,GGTbG,GDCaA,GC6BjB,IAAAG,GAnBA,WACC,MAEe,mBAAPD,IAGe,iBAAfF,IAGa,mBAAbH,ICST,IAAAvD,GAPA,WACC,MAAO,2BCEJ8D,GAAiBlE,GADHG,EAOL+D,GAAgB,SCjCR/D,MDsCrB,IAAAD,GAAiBgE,GEtCbxC,GAAcvB,EAwClB,ICpBAD,GDWKiE,MAAMC,QACND,MAAMC,QARX,SAAkBxE,GACjB,MAAkC,mBAAzB8B,GAAa9B,IEzBnBwE,GAAUjE,GC0Bd,ICGIkE,GDbJ,SAAuBzE,GACtB,OACW,OAAVA,GACiB,iBAAVA,GCQSO,EAOLkE,GAAc,oBFR3B,SAAmBC,GAClB,GAA0B,mBAAdA,EACX,MAAM,IAAI5E,UAAW,sDAAwD4E,EAAY,MAE1F,OASA,SAAgB1E,GACf,IAAI2E,EACAlC,EACJ,IAAM+B,GAASxE,GACd,OAAO,EAGR,GAAa,KADb2E,EAAM3E,EAAM0C,QAEX,OAAO,EAER,IAAMD,EAAI,EAAGA,EAAIkC,EAAKlC,IACrB,IAAiC,IAA5BiC,EAAW1E,EAAOyC,IACtB,OAAO,EAGT,OAAO,GEpBuCmC,CAAUH,KAK1D,IAAAnE,GAAiBmE,GCvCbA,GAAelE,GA+CnB,IC3BAD,GDOA,SAAmBN,GAClB,OACCyE,GAAczE,KAGbA,EAAM6E,WAEL7E,EAAM8E,aAGgC,mBAA/B9E,EAAM8E,YAAYC,UACzB/E,EAAM8E,YAAYC,SAAU/E,KEtC5B8B,GAAcvB,EACd6D,GAAKhE,GAA0C4E,OAC/CD,GAAW1E,GAuDf,IAAAG,GAxBA,SAA0BW,GACzB,IAAI8D,EACAC,EACAC,EAEJ,IAAe,YADfD,EAAOpD,GAAaX,GAAIiE,MAAO,GAAI,KACC,UAATF,IAAqB/D,EAAE2D,YAAc,CAE/D,GAA0B,iBAD1BK,EAAOhE,EAAE2D,aACQI,KAChB,OAAOC,EAAKD,KAGb,GADAD,EAAQb,GAAGiB,KAAMF,EAAKtG,YAErB,OAAOoG,EAAO,GAGhB,OAAKF,GAAU5D,GACP,SAED+D,GCnDJI,GCkBkB/E,GDmCtB,IErDI+E,GDkBkB/E,GCAtB,ICFIgF,GHkBJ,SAAiBpE,GAChB,IAAIqE,EAGJ,OAAW,OAANrE,EACG,OAKM,YAHdqE,SAAcrE,GAINmE,GAAUnE,GAAIsE,cAEfD,GG9BJlG,GDNJ,SAAiB6B,GAChB,OAAOmE,GAAUnE,GAAIsE,eCetBnF,GAZkBC,KAOajB,GAAWiG,GCtBtCA,GAAShF,GA2Bb,ICNAD,GDFA,SAAqBN,GAEpB,MAA6B,aAApBuF,GAAQvF,IErBdqF,GCFOK,OAAO/G,UAAU0G,KD0B5B,IEvBIvD,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADAqF,GAAKxF,KAAMG,IACJ,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBN,IA0CrB,IC1CIoF,GAAUpF,EACVqF,GAAaxF,GACbgC,GAAW/B,EAAsC4B,YACjD4D,GDuBJ,SAAmB7F,GAClB,MAAsB,iBAAVA,IACNA,aAAiB0F,SAGjB7E,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MC2BxB,ICvCAM,GDmBA,SAAkBiC,EAAKuD,EAAQC,GAC9B,IAAM3D,GAAUG,GACf,MAAM,IAAIzC,UAAW,wEAA0EyC,EAAM,MAEtG,GAAKH,GAAU0D,GACdA,EAASH,GAASG,GAClBA,EAAS,IAAIJ,OAAQI,EAAQ,UAEzB,IAAMD,GAAUC,GACpB,MAAM,IAAIhG,UAAW,+FAAiGgG,EAAS,MAEhI,IAAM1D,GAAU2D,KAAaH,GAAYG,GACxC,MAAM,IAAIjG,UAAW,gGAAkGiG,EAAS,MAEjI,OAAOxD,EAAII,QAASmD,EAAQC,IEhC7B,IAAAnF,GAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCAjBM,GCjBiB0F,OCAbnH,GCAS0B,GAMS5B,UAAUE,SDkBhC,IEvBIiD,GAAc1B,EACd4F,GAAS3F,GACT0B,GFSJ,SAAe/B,GACd,IAEC,OADAnB,GAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IETLqC,GARiBN,IA2CrB,IAAAyB,GAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiBgG,KAGjBnF,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MCnCpBiC,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd0F,GDfJ,SAAmBjG,GAClB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa8D,GAAU,cANL5F,IAOlB8B,GAAa8D,GAAU,WAAY/D,IAKnC,IAAA5B,GAAiB2F,GCvBjB3F,GALmB0F,OAAOE,kBCS1B5F,GA1BaC,GAqBa4F,kBChCtBC,GCsBQC,KAAKD,MDIjB,IENA9F,GFDA,SAAoBgG,GACnB,OAAQF,GAAME,KAAOA,GGpBlBC,GAAOhG,GACPiG,GAAOpG,GACPqG,GAAQpG,GAuBZ,IAAAqG,GAXA,SAAoB1G,GACnB,OACCA,EAAQuG,IACRvG,EAAQwG,IACRC,GAAOzG,IClBLiG,GAAW1F,GAAsC0B,YACjDwE,GAAQrG,GA6BZ,IAAAQ,GAVA,SAAoBZ,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,ICvBLiG,GAAW1F,GAAsC2B,SACjDuE,GAAQrG,GA6BZ,IAAA4B,GAVA,SAAoBhC,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICMI+B,GAAc5B,EACdoG,GDdJ,SAAoB3G,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICexCkC,GAAWG,GAKfF,GAAawE,GAAW,cANNtG,IAOlB8B,GAAawE,GAAW,WAAYzE,IAKpC,IAAA5B,GAAiBqG,GCvDbA,GAAYpG,GAAuC0B,YA6BvD,IAAArB,GAVA,SAA+BZ,GAC9B,OACC2G,GAAW3G,IACXA,GAAS,GCtBP2G,GAAYpG,GAAuC2B,SA6BvD,IAAAF,GAVA,SAA+BhC,GAC9B,OACC2G,GAAW3G,IACXA,EAAM4B,WAAa,GCtBjBK,GAAc1B,GACd2B,GAAW9B,GAsCf,ICGI+B,GAAc5B,EACdqG,GDXJ,SAA+B5G,GAC9B,OAASiC,GAAajC,IAAWkC,GAAUlC,ICYxCkC,GAAWG,GAKfF,GAAayE,GAAsB,cANjBvG,IAOlB8B,GAAayE,GAAsB,WAAY1E,IAK/C,IAAA5B,GAAiBsG,GCxDbC,GAAWvI,OAAOwI,eCatB,IAAAC,GARA,SAAmBxH,GAElB,OAAOA,EAAIQ,WCPR+B,GAAcvB,EACdsG,GAAWzG,GA+Bf,IAAAd,GAnBA,SAAyBC,GACxB,IAAIwH,EAAQF,GAAUtH,GACtB,OAAKwH,GAAmB,OAAVA,EACNA,EAEgC,sBAAnCjF,GAAavC,EAAIuF,aAEdvF,EAAIuF,YAAYnG,UAEnBY,aAAejB,OACZA,OAAOK,UAGR,MCzBJF,GHIaoI,GGHbvH,GAAWe,GCFXwG,GDAatG,GAQAjC,OAAOwI,gBACZrI,GAEAa,GCoBZ,ICdAgB,GDFA,SAAyBN,GACxB,OACCA,QAGO,MAGRA,EAAQ1B,OAAQ0B,GAET6G,GAAU7G,KEzBd8G,GAAiBvG,GACjBuB,GAAc1B,EAwClB,ICrBAE,GDAA,SAAkBN,GACjB,GAAsB,iBAAVA,GAAgC,OAAVA,EACjC,OAAO,EAGR,GAAKA,aAAiBC,MACrB,OAAO,EAGR,KAAQD,GAAQ,CACf,GAA8B,mBAAzB8B,GAAa9B,GACjB,OAAO,EAERA,EAAQ8G,GAAgB9G,GAEzB,OAAO,GEdR,IAAAQ,GAPA,WACC,MAAO,oCCWJwG,GAAW5G,GADGG,EAOLyG,GAAU,SChCRzG,UCAX6B,GAAW7B,EAAsC0B,YACjD+E,GFyCaA,GEXjB,ICdA1G,GDAA,SAAuBiC,GACtB,IAAMH,GAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAMrG,OAHAA,EAAMyE,KAAW3B,KAAM9C,IAGN,IAAImD,OAAQnD,EAAI,GAAIA,EAAI,IAAO,MEJjD,IAAA/B,GAPA,SAAgB8F,GACf,OAASA,GAAMA,GCfZL,GAAW1F,GAAsC0B,YACjDgF,GCcQ1G,GDmBZ,IAAAK,GAVA,SAAgBZ,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,IE3BLiG,GAAW1F,GAAsC2B,SACjD+E,GDcQ1G,GCeZ,IAAAyB,GAVA,SAAgBhC,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd2G,GDfJ,SAAgBlH,GACf,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa+E,GAAO,cANF7G,IAOlB8B,GAAa+E,GAAO,WAAYhF,IAKhC,IAAA5B,GAAiB4G,GCxDbP,GAAYpG,GAkChB,IClCI2G,GAAQ3G,GACR4G,GDmBJ,SAAuBnH,GACtB,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QENqB,kBDnBzBN,GAAW/B,EAAsC4B,YACjD0E,GAAYtE,GAAuCJ,YA0GvD,IAAAmF,GAhDA,SAAkBC,EAAKC,EAAeC,GACrC,IAAI5C,EACAlC,EACJ,IAAM0E,GAAcE,KAAUjF,GAAUiF,GACvC,MAAM,IAAIvH,UAAW,0EAA4EuH,EAAM,MAGxG,GAAa,KADb1C,EAAM0C,EAAI3E,QAET,OAAQ,EAET,GAA0B,IAArBmB,UAAUnB,OAAe,CAC7B,IAAMiE,GAAWY,GAChB,MAAM,IAAIzH,UAAW,6DAA+DyH,EAAY,MAEjG,GAAKA,GAAa,EAAI,CACrB,GAAKA,GAAa5C,EACjB,OAAQ,EAETlC,EAAI8E,OAEJ9E,EAAIkC,EAAM4C,GACD,IACR9E,EAAI,QAINA,EAAI,EAGL,GAAKyE,GAAOI,IACX,KAAQ7E,EAAIkC,EAAKlC,IAChB,GAAKyE,GAAOG,EAAI5E,IACf,OAAOA,OAIT,KAAQA,EAAIkC,EAAKlC,IAChB,GAAK4E,EAAK5E,KAAQ6E,EACjB,OAAO7E,EAIV,OAAQ,GErDTnC,GALcC,GClBd,IAAA9B,GAPA,SAAeuB,GACd,OAAO1B,OAAOkJ,KAAMlJ,OAAQ0B,KCrBzBwH,GAAOjH,GAmCX,IAAAkH,GAPA,WACC,OAlBD,WACC,OAA8C,KAArCD,GAAM3D,YAAe,IAAKnB,OAiB5BX,CAAM,EAAG,ICxBjB2F,QALoC,IAAhBpJ,OAAOkJ,KCAvB1F,GAAcvB,EA+BlB,IC1BIoH,GD0BJnH,GAPA,SAAsBR,GACrB,MAAkC,uBAAzB8B,GAAa9B,ICzBnB4H,GAAcrH,GA2BdsH,GAPJ,WACC,OAAOD,GAAa/D,WAMdiE,GAKP,IC3BIH,GD2BJI,GAAiBJ,GEDjBK,GAL2B1J,OAAOK,UAAUsJ,qBDHxCC,IAvBS3H,GAiBGV,KAAM,OAAQ,KAW9B,IE5BIuC,GAAW7B,EACX2G,GAAQ9G,GAAmC6B,YAC3C0E,GAAYtG,GAAuC4B,YACnDkG,GAAS9F,GACT+F,GFwBaT,GE6BjB,IAAAnH,GAzBA,SAA+BR,EAAOsB,GACrC,IAAIqG,EACJ,OACC3H,YAKD2H,EAAOQ,GAAOtI,KAAMG,EAAOsB,KACb8G,IAAoBhG,GAAUpC,IAIzCkH,GAFF5F,GAAYA,IAGXqF,GAAWrF,IACXA,GAAY,GACZA,EAAWtB,EAAM0C,OAGZiF,IC3BRrH,GAL2BC,GCnBvBiB,GAAajB,EACb8H,GAAuBjI,GACvBoE,GAAUnE,GACVsG,GAAYtE,GCiChB,IAAA/B,GAjBwBC,GACbH,GDQX,SAAsBJ,GACrB,OACW,OAAVA,GACiB,iBAAVA,IACNwE,GAASxE,IACc,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QAhCS4F,YAiCf9G,GAAYxB,EAAO,YAClBqI,GAAsBrI,EAAO,WEtC5B4H,GAAcrH,GACd9B,GAAU2B,GAKVgF,GAAQb,MAAM5F,UAAUyG,MA+B5B,IAAAmD,GAVA,SAAevI,GACd,OAAK4H,GAAa5H,GACVvB,GAAS2G,GAAMvF,KAAMG,IAEtBvB,GAASuB,ICnBjB,ICAAwI,GAZ2BjI,IDK3B,cCEuC,aCWvCkI,IAlB2BlI,GAKjB,CACT1B,SAAY,MAO0B,YCCvC,ICJI8I,GDIJe,GAPA,SAAiC1I,GAChC,OAASA,EAAM8E,aAAe9E,EAAM8E,YAAYnG,YAAcqB,GER3D2I,GAAwB,oBAAXtF,YAA2B,EAASA,ODAjD7B,GAAajB,EACbqI,GAAUxI,GACVmF,GAASlF,GACTwI,GAAyBxG,GACzByG,wPACAC,GCAaJ,GD2CbK,GAzBJ,WACC,IAAIC,EACJ,GAAuB,cAAlB1D,GAAQwD,IACZ,OAAO,EAER,IAAME,KAAKF,GACV,KAEmC,IAAjCH,GAASE,GAAeG,IACxBzH,GAAYuH,GAAKE,IACJ,OAAbF,GAAKE,IACkB,WAAvB1D,GAAQwD,GAAKE,KAEbJ,GAAwBE,GAAKE,IAE7B,MAAQzK,GACT,OAAO,EAGT,OAAO,EAMD0K,GAKP,IErDIvB,GAA2B,oBAAXtE,OCAhB8F,GHqDaxB,GGpDbkB,GAAyBzI,GACzBgJ,GDGazB,GCuBjB,IC5BIlD,GAAelE,GACfiB,GAAapB,EACbwH,GAAcvH,GACdgJ,GAAqBhH,GACrBiH,GAAyBhB,GACzBO,GDSJ,SAAkB7I,GACjB,IAAoB,IAAfoJ,KAAyBD,GAC7B,OAAON,GAAwB7I,GAEhC,IACC,OAAO6I,GAAwB7I,GAC9B,MAAQuJ,GACT,OAAO,ICfLC,iHAyEJ,IC7EI/K,GAAU4B,GACVoJ,GAAUpH,GACV/C,GDuBJ,SAAeU,GACd,IAAI0J,EACAC,EACAC,EACAjI,EACAsH,EACAY,EACApH,EAGJ,GADAd,EAAM,GACDiG,GAAa5H,GAAU,CAE3B,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,YAGb,OAAO8C,EAER,GAAsB,iBAAV3B,GAEX,GAAKA,EAAM0C,OAAS,IAAMlB,GAAYxB,EAAO,KAC5C,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,gBAGR,CAEN,IAAe,KADf+K,EAA2B,mBAAV5J,KACQyE,GAAczE,GACtC,OAAO2B,EAERgI,EAAkBN,IAAsBO,EAEzC,IAAMX,KAAKjJ,EACF2J,GAAuB,cAANV,IAAuBzH,GAAYxB,EAAOiJ,IAClEtH,EAAImI,KAAMjI,OAAQoH,IAGpB,GAAKK,GAEJ,IADAI,EAAkBb,GAAwB7I,GACpCyC,EAAI,EAAGA,EAAI+G,GAAe9G,OAAQD,IACvCoH,EAAIL,GAAgB/G,GACZiH,GAAyB,gBAANG,IAAyBrI,GAAYxB,EAAO6J,IACtElI,EAAImI,KAAMjI,OAAQgI,IAIrB,OAAOlI,GEnDRrB,GDrBkBF,GADIG,KA6BbkJ,GAEAhL,GAGDa,GE7BRoI,QALmD,IAA/BpJ,OAAOyL,oBCAvBC,GAAgB1L,OAAOyL,oBAgC3B,IChCIvC,GAAOjH,GCgCX,IAAAD,GAjBkBC,GFUlB,SAA8BP,GAC7B,OAAOgK,GAAe1L,OAAQ0B,KCA/B,SAA8BA,GAC7B,OAAOwH,GAAMlJ,OAAQ0B,KEtBtB0H,QALwD,IAApCpJ,OAAO2L,yBCAvBC,GAAqB5L,OAAO2L,yBAuChC,ICvCIzI,GAAajB,ECkCjB,IAAAD,GAjBkBC,GFUlB,SAAmCP,EAAOsB,GACzC,IAAI6I,EACJ,OAAKnK,cAIa,KADlBmK,EAAOD,GAAoBlK,EAAOsB,IAF1B,KAG4B6I,GCLrC,SAAmCnK,EAAOsB,GACzC,OAAKE,GAAYxB,EAAOsB,GAChB,CACNb,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,EAAOsB,IAGX,o4qBErCJd,GAA0C4J,GAK9C7G,OAAOC,QAAUhD,OCLbuE,GAAWxE,GACX8J,sCA4CJ,IAAA7J,GA9BA,WACC,IAAImH,EACA2C,EAEJ,GAA6B,mBAAjBD,GACX,OAAO,EAGR,IAEEC,EADiC,mBAAtBD,GAAaE,KACpBF,GAAaE,KAAM,CAAE,EAAG,EAAG,EAAG,IAE9B,IAAIF,GAAc,CAAE,EAAG,EAAG,EAAG,IAElC1C,EACC5C,GAAUuF,IACC,IAAXA,EAAG,IACQ,IAAXA,EAAG,IACQ,IAAXA,EAAG,IACQ,IAAXA,EAAG,GAEH,MAAQ9L,GACTmJ,GAAO,EAER,OAAOA,GCtBRrH,GAL2BC,GCE3B,ICDIC,SCb2B4J,ODc3B9K,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GAjB2BC,KASnBC,GAEAlB,GEjBJqI,GANapH,GACJH,GAKiBmK,MCN1BxF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAI,GAVA,SAAqBgK,GACpB,IAAMzF,GAAUyF,GACf,MAAM,IAAI1K,UAAW,oDAAsD0K,EAAS,KAErF,OAAOJ,GAAOG,KAAMC,IC1BjBzF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAd,GAVA,SAAqBkL,GACpB,IAAMzF,GAAUyF,GACf,MAAM,IAAI1K,UAAW,oDAAsD0K,EAAS,KAErF,OAAO,IAAIJ,GAAQI,ICOpBlK,GHtBiBqH,GGMNvH,GACIC,GClBXyB,GAAcvB,EAKdkK,GAAsC,mBAAdtG,UA6B5B,IClCI3D,GAA8B,mBAAd2D,UAA6BA,UAAY,KCAzDuG,GFwBJ,SAAsB1K,GACrB,OACGyK,IAAgBzK,aAAiBmE,WACV,uBAAzBrC,GAAa9B,IExBX2K,GDEanK,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAgC,mBAApBsD,GACX,OAAO,EAGR,IACCtD,EAAM,IAAIsD,GAAiB,CAAE,EAAG,MAAO,KAAMC,MAC7CjD,EACC+C,GAAarD,IACA,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEO,MDDZA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb8B,mBAAd0F,UAA6BA,eAAY,EDczD7E,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB0BC,KFSlB9B,GAEAa,GGvBJwC,GAAcvB,EAKdsK,GAAwC,mBAAfC,WA6B7B,IClCItK,GAA+B,mBAAfsK,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuB/K,GACtB,OACG6K,IAAiB7K,aAAiB8K,YACX,wBAAzBhJ,GAAa9B,IEzBXgL,GDGaxK,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB2D,GACX,OAAO,EAGR,IAEC3D,EAAM,IAAI2D,GADV3D,EAAM,CAAE,EAAG,MAAO,KAAM4D,IAAaA,MAErCtD,EACCoD,GAAc1D,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ4D,MAAb5D,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCb+B,mBAAfqM,WAA8BA,gBAAa,EDc3DxL,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd2K,GAAsD,mBAAtBC,kBA6BpC,IClCI3K,GAAsC,mBAAtB2K,kBAAqCA,kBAAoB,KCAzEC,GFwBJ,SAA8BpL,GAC7B,OACGkL,IAAwBlL,aAAiBmL,mBAClB,+BAAzBrJ,GAAa9B,IE1BXqL,GDIa7K,GCuCjB,IAAAA,GA7BA,WACC,IAAImH,EACAN,EAEJ,GAAwC,mBAA5BgE,GACX,OAAO,EAGR,IACChE,EAAM,IAAIgE,GAAyB,EAAG,EAAG,EAAG,EAAG,KAAM,KAAM,IAAK,MAChE1D,EACCyD,GAAqB/D,IACR,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,MAAbA,EAAK,IACQ,MAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbsC,mBAAtB0M,kBAAqCA,uBAAoB,EDczE7L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjBkCC,KFS1B9B,GAEAa,GGvBJwC,GAAcvB,EAKd+K,GAAwC,mBAAfC,WA6B7B,IClCI/K,GAA+B,mBAAf+K,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBxL,GACtB,OACGsL,IAAiBtL,aAAiBuL,YACX,wBAAzBzJ,GAAa9B,IExBXyL,GDEajL,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArBoE,GACX,OAAO,EAGR,IACCpE,EAAM,IAAIoE,GAAkB,CAAE,EAAG,MAAO,KAAMC,QAC9C/D,EACC6D,GAAcnE,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,QDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAf8M,WAA8BA,gBAAa,EDc3DjM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdoL,GAA0C,mBAAhBC,YA6B9B,IClCIpL,GAAgC,mBAAhBoL,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwB7L,GACvB,OACG2L,IAAkB3L,aAAiB4L,aACZ,yBAAzB9J,GAAa9B,IEzBX8L,GDGatL,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtByE,GACX,OAAO,EAGR,IAECzE,EAAM,IAAIyE,GADVzE,EAAM,CAAE,EAAG,MAAO,KAAM0E,MAAcA,QAEtCpE,EACCkE,GAAexE,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ0E,QAAb1E,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhBmN,YAA+BA,iBAAc,EDc7DtM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdyL,GAAwC,mBAAfC,WA6B7B,IClCIzL,GAA+B,mBAAfyL,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBlM,GACtB,OACGgM,IAAiBhM,aAAiBiM,YACX,wBAAzBnK,GAAa9B,IExBXmM,GDEa3L,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB8E,GACX,OAAO,EAGR,IACC9E,EAAM,IAAI8E,GAAkB,CAAE,EAAG,MAAO,KAAMC,aAC9CzE,EACCuE,GAAc7E,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,aDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAfwN,WAA8BA,gBAAa,EDc3D3M,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd8L,GAA0C,mBAAhBC,YA6B9B,IClCI9L,GAAgC,mBAAhB8L,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwBvM,GACvB,OACGqM,IAAkBrM,aAAiBsM,aACZ,yBAAzBxK,GAAa9B,IEzBXwM,GDGahM,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBmF,GACX,OAAO,EAGR,IAECnF,EAAM,IAAImF,GADVnF,EAAM,CAAE,EAAG,MAAO,KAAMoF,WAAcA,aAEtC9E,EACC4E,GAAelF,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQoF,aAAbpF,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhB6N,YAA+BA,iBAAc,EDc7DhN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdmM,GAA4C,mBAAjBC,aA6B/B,IClCInM,GAAiC,mBAAjBmM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB5M,GACxB,OACG0M,IAAmB1M,aAAiB2M,cACb,0BAAzB7K,GAAa9B,IE1BXuG,GAAOnG,GACPyM,GDGarM,GCqCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvBwF,GACX,OAAO,EAGR,IACCxF,EAAM,IAAIwF,GAAoB,CAAE,EAAK,MAAO,KAAM,OAClDlF,EACCiF,GAAgBvF,IACH,IAAbA,EAAK,IACQ,oBAAbA,EAAK,KACS,oBAAdA,EAAK,IACLA,EAAK,KAAQd,GAEb,MAAQ/H,GACTmJ,GAAO,EAER,OAAOA,GCtBR,ICDIlJ,GCbiC,mBAAjBkO,aAAgCA,kBAAe,EDc/DrN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB6BC,KFSrB9B,GAEAa,GGvBJwC,GAAcvB,EAKduM,GAA4C,mBAAjBC,aA6B/B,IClCIvM,GAAiC,mBAAjBuM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyBhN,GACxB,OACG8M,IAAmB9M,aAAiB+M,cACb,0BAAzBjL,GAAa9B,IE1BXiN,GDIazM,GCoCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvB4F,GACX,OAAO,EAGR,IACC5F,EAAM,IAAI4F,GAAoB,CAAE,EAAK,MAAO,KAAMC,MAClDvF,EACCqF,GAAgB3F,IACH,IAAbA,EAAK,IACQ,OAAbA,EAAK,KACS,OAAdA,EAAK,IACLA,EAAK,IAAQA,EAAK,GAElB,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCrBR,ICKIxC,GANA1G,GCbiC,mBAAjBsO,aAAgCA,kBAAe,EDc/DzN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCajBkF,GET4B5E,KFSrB9B,GAEAa,GAMR,IG7BI6E,GAAY5D,GACZuK,GAAa1K,GACb+K,GAAoB9K,GACpBkL,GAAalJ,GACbuJ,GAActD,GACd2D,GAAakB,GACbb,GAAcc,GACdT,GAAeU,GACfN,GHqBa5H,GGJjB,SAASmI,GAAWjG,GACnB,OAAO,IAAIlD,GAAWkD,GAUvB,SAASkG,GAAYlG,GACpB,OAAO,IAAIyD,GAAYzD,GAUxB,SAASmG,GAAmBnG,GAC3B,OAAO,IAAI8D,GAAmB9D,GAU/B,SAASoG,GAAYpG,GACpB,OAAO,IAAIkE,GAAYlE,GAUxB,SAASqG,GAAarG,GACrB,OAAO,IAAIuE,GAAavE,GAUzB,SAASsG,GAAYtG,GACpB,OAAO,IAAI4E,GAAY5E,GAUxB,SAASuG,GAAavG,GACrB,OAAO,IAAIiF,GAAajF,GAUzB,SAASwG,GAAcxG,GACtB,OAAO,IAAIsF,GAActF,GAU1B,SAASyG,GAAczG,GACtB,OAAO,IAAI0F,GAAc1F,GAgC1B,IClJI7F,GAAajB,EACbiE,GAAUpE,GACV2E,GAAW1E,GACX0N,GAAU1L,GACVkD,GAAS+C,GACT0F,GAASb,GACTvE,GAAUwE,GACVa,GAAaZ,GACbrD,GAAgBkE,GAChBhE,GAAqBiE,GACrBrH,GAAiBsH,GACjB/P,GAAiBgQ,EACjBC,GAAaC,GACbC,GD+GO,CACTlB,UAAaA,GACbC,WAAcA,GACdC,kBAAqBA,GACrBC,WAAcA,GACdC,YAAeA,GACfC,WAAcA,GACdC,YAAeA,GACfC,aAAgBA,GAChBC,aAAgBA,ICQlB,SAASW,GAAUC,EAAKC,EAAMC,EAAOC,EAAMC,GAC1C,IAAIC,EACAvH,EACAtC,EACAiF,EACAhF,EACA6J,EACAC,EACA3I,EACA7D,EACAyM,EAKJ,GAHAJ,GAAS,EAIO,iBAARJ,GACC,OAARA,EAEA,OAAOA,EAER,GAAK3J,GAAU2J,GACd,OAAOJ,GAAYI,GAEpB,GAAKX,GAASW,GACb,OAnFF,SAAoBnF,GACnB,IAEI/B,EACA2C,EACAgF,EACAH,EACAxQ,EACAiE,EAPAmM,EAAQ,GACRC,EAAO,GA8BX,IArBArQ,EAAM,IAAI+K,EAAMzE,YAAayE,EAAM6F,SAEnCR,EAAM9E,KAAMP,GACZsF,EAAK/E,KAAMtL,GAGN+K,EAAM8F,QACV7Q,EAAI6Q,MAAQ9F,EAAM8F,OAGd9F,EAAM+F,OACV9Q,EAAI8Q,KAAO/F,EAAM+F,MAEb/F,EAAMgG,QACV/Q,EAAI+Q,MAAQhG,EAAMgG,OAEdhG,EAAMiG,UACVhR,EAAIgR,QAAUjG,EAAMiG,SAGrBhI,EAAOyG,GAAY1E,GACb9G,EAAI,EAAGA,EAAI+E,EAAK9E,OAAQD,IAC7BuM,EAAMxH,EAAM/E,GACZ0H,EAAOD,GAAoBX,EAAOyF,GAC7BxN,GAAY2I,EAAM,WACtBgF,EAAQ3K,GAAS+E,EAAOyF,IAAY,GAAK,GACzC7E,EAAKnK,MAAQyO,GAAUlF,EAAOyF,GAAOG,EAAKP,EAAOC,GAAO,IAEzDxQ,GAAgBG,EAAKwQ,EAAK7E,GAE3B,OAAO3L,EA0CCiR,CAAWf,GAKnB,GAAc,UAFdxJ,EAAOK,GAAQmJ,IAGd,OAAO,IAAIgB,MAAOhB,GAEnB,GAAc,WAATxJ,EACJ,OAAO8I,GAAQU,EAAI7P,YAEpB,GAAc,QAATqG,EACJ,OAAO,IAAIyK,IAAKjB,GAEjB,GAAc,QAATxJ,EACJ,OAAO,IAAI0K,IAAKlB,GAEjB,GACU,WAATxJ,GACS,YAATA,GACS,WAATA,EAGA,OAAOwJ,EAAI9M,UAGZ,GADAuD,EAAOqJ,GAAatJ,GAEnB,OAAOC,EAAMuJ,GAGd,GACU,UAATxJ,GACS,WAATA,EAGA,MAA8B,mBAAlB5G,OAAOuR,OA1KrB,SAAwBnB,GACvB,IAAIE,EACAkB,EACA5K,EACA2J,EACA1E,EACAgF,EACAF,EACAxM,EAUJ,IARAmM,EAAQ,GACRC,EAAO,GAEPI,EAAM3Q,OAAOyR,OAAQjJ,GAAgB4H,IACrCE,EAAM9E,KAAM4E,GACZG,EAAK/E,KAAMmF,GAEXa,EAAQ9F,GAAe0E,GACjBjM,EAAI,EAAGA,EAAIqN,EAAMpN,OAAQD,IAC9ByC,EAAO4K,EAAOrN,GACd0H,EAAOD,GAAoBwE,EAAKxJ,GAC3B1D,GAAY2I,EAAM,WACtBgF,EAAQ3K,GAASkK,EAAIxJ,IAAY,GAAK,GACtCiF,EAAKnK,MAAQyO,GAAUC,EAAIxJ,GAAOiK,EAAKP,EAAOC,GAAO,IAEtDxQ,GAAgB4Q,EAAK/J,EAAMiF,GAW5B,OATM7L,OAAO0R,aAActB,IAC1BpQ,OAAO2R,kBAAmBhB,GAEtB3Q,OAAO4R,SAAUxB,IACrBpQ,OAAO6R,KAAMlB,GAET3Q,OAAO8R,SAAU1B,IACrBpQ,OAAOuR,OAAQZ,GAETA,EAuIEoB,CAAe3B,GAEhB,GAIR,GADAlH,EAAOyG,GAAYS,GACdI,EAAQ,EAEZ,IADAC,EAAS7J,EACHgK,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAE7B5I,EAAIoI,EADJM,EAAMxH,EAAM0H,IAIZhK,EAAOK,GAAQe,GAED,iBAANA,GACD,OAANA,GAEU,UAATpB,GACS,WAATA,GAEDH,GAAUuB,GAEM,WAAXyI,GACJ5E,EAAOD,GAAoBwE,EAAKM,GAC3BxN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQyO,GAAUnI,IAExBjI,GAAgBsQ,EAAMK,EAAK7E,IAE3BwE,EAAMK,GAAQP,GAAUnI,IAMd,KADZ7D,EAAImG,GAASgG,EAAOtI,KAMpB2I,EAAQzK,GAAS8B,GAAQ,IAAI/B,MAAO+B,EAAE5D,QAAW,GACjDkM,EAAM9E,KAAMxD,GACZuI,EAAK/E,KAAMmF,GACK,UAAXF,EACJJ,EAAMK,GAAQP,GAAUnI,EAAG2I,EAAKL,EAAOC,EAAMC,IAE7C3E,EAAOD,GAAoBwE,EAAKM,GAC3BxN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQyO,GAAUnI,EAAG2I,EAAKL,EAAOC,EAAMC,IAE7CzQ,GAAgBsQ,EAAMK,EAAK7E,KAd3BwE,EAAMK,GAAQH,EAAMpM,QAiBhB,GAAc,UAATyC,EACX,IAAMgK,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAE7BP,EADAK,EAAMxH,EAAM0H,IACER,EAAKM,QAGpB,IAAME,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAC7BF,EAAMxH,EAAM0H,GACZ/E,EAAOD,GAAoBwE,EAAKM,GAChC3Q,GAAgBsQ,EAAMK,EAAK7E,GAY7B,OATM7L,OAAO0R,aAActB,IAC1BpQ,OAAO2R,kBAAmBtB,GAEtBrQ,OAAO4R,SAAUxB,IACrBpQ,OAAO6R,KAAMxB,GAETrQ,OAAO8R,SAAU1B,IACrBpQ,OAAOuR,OAAQlB,GAETA,EAMR,IC3RInK,GAAUjE,GACVqG,GAAuBxG,GAAmD6B,YAC1EsE,GAAOlG,GACPoO,GDwRaA,GCtOjB,IAAA6B,GAnBA,SAAetQ,EAAO8O,GACrB,IAAInN,EACJ,GAAKkC,UAAUnB,OAAS,EAAI,CAC3B,IAAMkE,GAAsBkI,GAC3B,MAAM,IAAIhP,UAAW,oEAAsEgP,EAAQ,MAEpG,GAAe,IAAVA,EACJ,OAAO9O,OAGR8O,EAAQvI,GAGT,OADA5E,EAAQ6C,GAASxE,GAAY,IAAIuE,MAAOvE,EAAM0C,QAAW,GAClD+L,GAAUzO,EAAO2B,EAAK,CAAC3B,GAAQ,CAAC2B,GAAMmN,ICd9CxO,GALWC,GC5BPiE,GAAUjE,GA8Bd,IC9BI2B,GDmBJ,SAAmBlC,GAClB,MACkB,iBAAVA,GACG,OAAVA,IACCwE,GAASxE,ICtBR4F,GAAaxF,GACb0G,GAAiBzG,GACjBmB,GAAaa,EACbP,GAAcwG,EAKdiI,GAAkBjS,OAAOK,UAgF7B,IAAA6B,GAvCA,SAAwBR,GACvB,IAAI+G,EAGJ,QAAM7E,GAAUlC,OAIhB+G,EAAQD,GAAgB9G,MAOtBwB,GAAYxB,EAAO,gBAGpBwB,GAAYuF,EAAO,gBACnBnB,GAAYmB,EAAMjC,cACmB,sBAArChD,GAAaiF,EAAMjC,cAGnBtD,GAAYuF,EAAO,kBACnBnB,GAAYmB,EAAMyJ,iBAIjBzJ,IAAUwJ,IAzDb,SAAmBhR,GAClB,IAAIyP,EAGJ,IAAMA,KAAOzP,EACZ,IAAMiC,GAAYjC,EAAKyP,GACtB,OAAO,EAGT,OAAO,EAmDLyB,CAAUzQ,MCjFTkC,GCegB3B,GDdhBiB,GAAapB,EACbgC,GAAW/B,EAAsC4B,YAqCrD,wJEvCIU,GAAUpC,GACVoO,GAAOvO,GACPsQ,GFeJ,SAAmBC,EAAMC,GACxB,OAAM1O,GAAU0O,GAGXpP,GAAYoP,EAAS,SACzBD,EAAKE,IAAMD,EAAQC,KACbzO,GAAUuO,EAAKE,MACb,IAAI/Q,UAAW,qEAAuE6Q,EAAKE,IAAM,MAGrGrP,GAAYoP,EAAS,aACzBD,EAAKvB,QAAUwB,EAAQxB,SACjBhN,GAAUuO,EAAKvB,UACb,IAAItP,UAAW,yEAA2E6Q,EAAKvB,QAAU,MAG3G,KAdC,IAAItP,UAAW,iEAAmE8Q,EAAU,OEhBjGE,GAAWzO,GAwDf,IAAA0O,GAnCA,SAAkBH,GACjB,IAAID,EACAnS,EAGJ,GAFAmS,EAAOhC,GAAMmC,IACbtS,EAAMkS,GAAUC,EAAMC,GAErB,MAAMpS,EAEP,OAUA,WACC,IAEIwS,EACAvO,EAHA6M,EAAOzL,UAAW,GAClBgN,EAAMF,EAAKE,IAAM,SAASvB,EAG9B,IAAM7M,EAAI,EAAGA,EAAIoB,UAAUnB,OAAQD,IAClCoO,GAAO,UAAYI,mBAAoBpN,UAAWpB,IAInD,OAFAuO,EAAMrO,GAASgO,EAAKvB,QAAS,UAAWyB,GACxCG,EAAMrO,GAASqO,EAAK,WAAY1B,KCtC9B4B,GCbU3Q,GACCH,IDWGG,EAOL2Q,GAAwB,UALvB7Q,IAUd,IAAAC,GAAiB4Q,UEiFjB,WACC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAnP,EACA0M,EACAzM,EASJ,IANA0O,EAAUtN,UAAW,GACrBuN,EAASvN,UAAW,GAGpBwN,GADAG,EAAQ3N,UAAW,GADnB0N,GAHAD,EAAQzN,UAAW,IAGLnB,UAECA,OACfgP,EAAMN,EACA3O,EAAI,EAAGA,EAAI8O,EAAO9O,IAAM,CAI7B,GAHAkP,EAAIL,EAAO7O,GACXyM,EAAIrL,UAAWpB,EAAE,GAEH,WADdgP,EAAOD,EAAO/O,EAAE4O,IAEVnC,EAAI,EACRA,EAAI,EACOA,GAAKyC,IAChBzC,EAAIyC,EAAI,QAEH,GAAc,SAATF,EACNvC,EAAI,GACRA,GAAKyC,GACI,GAEG,KADXzC,GAAKyC,KAEJzC,GAAKyC,GAGIzC,GAAKyC,IAChBzC,GAAKyC,IACKA,IACTzC,GAAKyC,QAGD,GAAKzC,EAAI,GAAKA,GAAKyC,EACzB,MAAM,IAAIC,WAAYC,GAAQ,+FAAgGpP,EAAGyM,KAElI1M,EAAI2O,EAAS1O,IAGJ,GAAgB,IAAX2O,EACbM,GAAOxC,EAAI1M,EAEXkP,GAAOxC,EAAI1M,EAGb,OAAOkP"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index be5ab40..50c5e03 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./browser.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..7edaeaa --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..b60f829 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From c51e86fb4ab6e753b3c61841514ec961d97ee7d5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 19:23:33 +0000 Subject: [PATCH 005/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index bc49a2b..be5ab40 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From bad91b0adebcf8d8d492e7697e9ac9a35315fe84 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 12:33:36 +0000 Subject: [PATCH 006/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 319dc4e..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).sub2ind=r()}(this,(function(){"use strict";function t(t){var r=t.default;if("function"==typeof r){var e=function(){return r.apply(this,arguments)};e.prototype=r.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(t).forEach((function(r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})})),e}var r="function"==typeof Object.defineProperty?Object.defineProperty:null;var e=function(){try{return r({},"x",{}),!0}catch(t){return!1}},n=Object.defineProperty,o=Object.prototype,i=o.toString,u=o.__defineGetter__,a=o.__defineSetter__,f=o.__lookupGetter__,c=o.__lookupSetter__;var s=function(t,r,e){var n,s,l,h;if("object"!=typeof t||null===t||"[object Array]"===i.call(t))throw new TypeError("invalid argument. First argument must be an object. Value: `"+t+"`.");if("object"!=typeof e||null===e||"[object Array]"===i.call(e))throw new TypeError("invalid argument. Property descriptor must be an object. Value: `"+e+"`.");if((s="value"in e)&&(f.call(t,r)||c.call(t,r)?(n=t.__proto__,t.__proto__=o,delete t[r],t[r]=e.value,t.__proto__=n):t[r]=e.value),l="get"in e,h="set"in e,s&&(l||h))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return l&&u&&u.call(t,r,e.get),h&&a&&a.call(t,r,e.set),t},l=n,h=s,p=e()?l:h,y=p;var v=function(t,r,e){y(t,r,{configurable:!1,enumerable:!1,writable:!1,value:e})},g=v;var w=function(t){return"string"==typeof t};var d=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var b=function(){return d&&"symbol"==typeof Symbol.toStringTag},m=Object.prototype.toString,A=m;var E=function(t){return A.call(t)},_=Object.prototype.hasOwnProperty;var O=function(t,r){return null!=t&&_.call(t,r)},P="function"==typeof Symbol?Symbol.toStringTag:"",j=O,R=P,T=m;var U=E,S=function(t){var r,e,n;if(null==t)return T.call(t);e=t[R],r=j(t,R);try{t[R]=void 0}catch(r){return T.call(t)}return n=T.call(t),r?t[R]=e:delete t[R],n},I=b()?S:U,B=String.prototype.valueOf;var Y=I,x=function(t){try{return B.call(t),!0}catch(t){return!1}},C=b();var M=function(t){return"object"==typeof t&&(t instanceof String||(C?x(t):"[object String]"===Y(t)))},L=w,F=M;var D=g,N=function(t){return L(t)||F(t)},k=M;D(N,"isPrimitive",w),D(N,"isObject",k);var V=N,z=V.isPrimitive,G=/[-\/\\^$*+?.()|[\]{}]/g;var X=function(t){var r,e;if(!z(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");if("/"===t[0])for(e=t.length-1;e>=0&&"/"!==t[e];e--);return void 0===e||e<=0?t.replace(G,"\\$&"):(r=(r=t.substring(1,e)).replace(G,"\\$&"),t=t[0]+r+t.substring(e))},$=/./;var H=function(t){return"boolean"==typeof t},W=Boolean.prototype.toString;var q=I,J=function(t){try{return W.call(t),!0}catch(t){return!1}},Z=b();var K=function(t){return"object"==typeof t&&(t instanceof Boolean||(Z?J(t):"[object Boolean]"===q(t)))},Q=H,tt=K;var rt=g,et=function(t){return Q(t)||tt(t)},nt=K;rt(et,"isPrimitive",H),rt(et,"isObject",nt);var ot=et;var it=function(){return new Function("return this;")()},ut="object"==typeof self?self:null,at="object"==typeof window?window:null,ft="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},ct="object"==typeof ft?ft:null;module.exports=ct;var st=ot.isPrimitive,lt=it,ht=ut,pt=at,yt=t(Object.freeze({__proto__:null}));var vt=function(t){if(arguments.length){if(!st(t))throw new TypeError("invalid argument. Must provide a boolean primitive. Value: `"+t+"`.");if(t)return lt()}if(ht)return ht;if(pt)return pt;if(yt)return yt;throw new Error("unexpected error. Unable to resolve global object.")},gt=vt(),wt=gt.document&>.document.childNodes,dt=Int8Array,bt=$,mt=wt,At=dt;var Et=function(){return"function"==typeof bt||"object"==typeof At||"function"==typeof mt};var _t=function(){return/^\s*function\s*([^(]*)/i},Ot=_t;g(Ot,"REGEXP",_t());var Pt=Ot,jt=I;var Rt=Array.isArray?Array.isArray:function(t){return"[object Array]"===jt(t)},Tt=Rt;var Ut=function(t){return null!==t&&"object"==typeof t};g(Ut,"isObjectLikeArray",function(t){if("function"!=typeof t)throw new TypeError("invalid argument. Must provide a function. Value: `"+t+"`.");return function(r){var e,n;if(!Tt(r))return!1;if(0===(e=r.length))return!1;for(n=0;ndr&&br(t)},Ar=hr.isPrimitive,Er=mr;var _r=function(t){return Ar(t)&&Er(t)},Or=hr.isObject,Pr=mr;var jr=function(t){return Or(t)&&Pr(t.valueOf())},Rr=_r,Tr=jr;var Ur=g,Sr=function(t){return Rr(t)||Tr(t)},Ir=jr;Ur(Sr,"isPrimitive",_r),Ur(Sr,"isObject",Ir);var Br=Sr,Yr=Br.isPrimitive;var xr=function(t){return Yr(t)&&t>=0},Cr=Br.isObject;var Mr=function(t){return Cr(t)&&t.valueOf()>=0},Lr=xr,Fr=Mr;var Dr=g,Nr=function(t){return Lr(t)||Fr(t)},kr=Mr;Dr(Nr,"isPrimitive",xr),Dr(Nr,"isObject",kr);var Vr=Nr,zr=Object.getPrototypeOf;var Gr=function(t){return t.__proto__},Xr=I,$r=Gr;var Hr=function(t){var r=$r(t);return r||null===r?r:"[object Function]"===Xr(t.constructor)?t.constructor.prototype:t instanceof Object?Object.prototype:null},Wr=zr,qr=Hr,Jr=zt(Object.getPrototypeOf)?Wr:qr;var Zr=function(t){return null==t?null:(t=Object(t),Jr(t))},Kr=Zr,Qr=I;var te=function(t){if("object"!=typeof t||null===t)return!1;if(t instanceof Error)return!0;for(;t;){if("[object Error]"===Qr(t))return!0;t=Kr(t)}return!1};var re=function(){return/^\/((?:\\\/|[^\/])+)\/([imgy]*)$/},ee=re;g(ee,"REGEXP",re());var ne=V.isPrimitive,oe=ee;var ie=function(t){if(!ne(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");return(t=oe().exec(t))?new RegExp(t[1],t[2]):null};var ue=function(t){return t!=t},ae=hr.isPrimitive,fe=ue;var ce=function(t){return ae(t)&&fe(t)},se=hr.isObject,le=ue;var he=function(t){return se(t)&&le(t.valueOf())},pe=ce,ye=he;var ve=g,ge=function(t){return pe(t)||ye(t)},we=he;ve(ge,"isPrimitive",ce),ve(ge,"isObject",we);var de=ge,be=gr;var me=de,Ae=function(t){return"object"==typeof t&&null!==t&&"number"==typeof t.length&&be(t.length)&&t.length>=0&&t.length<=9007199254740991},Ee=V.isPrimitive,_e=Br.isPrimitive;var Oe=function(t,r,e){var n,o;if(!Ae(t)&&!Ee(t))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+t+"`.");if(0===(n=t.length))return-1;if(3===arguments.length){if(!_e(e))throw new TypeError("invalid argument. `fromIndex` must be an integer. Value: `"+e+"`.");if(e>=0){if(e>=n)return-1;o=e}else(o=n+e)<0&&(o=0)}else o=0;if(me(r)){for(;o=0&&r=0&&t.length<=4294967295&&Ge(t,"callee")&&!Xe(t,"callee")},qe=We,Je=je,Ze=Array.prototype.slice;var Ke=function(t){return qe(t)?Je(Ze.call(t)):Je(t)};var Qe=ze((function(){}),"prototype"),tn=!ze({toString:null},"toString");var rn,en=function(t){return t.constructor&&t.constructor.prototype===t},nn="undefined"==typeof window?void 0:window,on=O,un=Pe,an=kt,fn=en,cn=["console","external","frame","frameElement","frames","innerHeight","innerWidth","outerHeight","outerWidth","pageXOffset","pageYOffset","parent","scrollLeft","scrollTop","scrollX","scrollY","self","webkitIndexedDB","webkitStorageInfo","window"],sn=nn;rn=function(){var t;if("undefined"===an(sn))return!1;for(t in sn)try{-1===un(cn,t)&&on(sn,t)&&null!==sn[t]&&"object"===an(sn[t])&&fn(sn[t])}catch(t){return!0}return!1}();var ln="undefined"!=typeof window,hn=rn,pn=en,yn=ln;var vn=St,gn=O,wn=We,dn=Qe,bn=tn,mn=function(t){if(!1===yn&&!hn)return pn(t);try{return pn(t)}catch(t){return!1}},An=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"];var En=je,_n=Ke,On=function(t){var r,e,n,o,i,u,a;if(o=[],wn(t)){for(a=0;a0&&!gn(t,"0"))for(a=0;a!1})),Cn=[],Mn=[],Ln="undefined"!=typeof Uint8Array?Uint8Array:Array,Fn=!1;function Dn(){Fn=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=0,e=t.length;r>18&63]+Cn[o>>12&63]+Cn[o>>6&63]+Cn[63&o]);return i.join("")}function kn(t){var r;Fn||Dn();for(var e=t.length,n=e%3,o="",i=[],u=16383,a=0,f=e-n;af?f:a+u));return 1===n?(r=t[e-1],o+=Cn[r>>2],o+=Cn[r<<4&63],o+="=="):2===n&&(r=(t[e-2]<<8)+t[e-1],o+=Cn[r>>10],o+=Cn[r>>4&63],o+=Cn[r<<2&63],o+="="),i.push(o),i.join("")}function Vn(t,r,e,n,o){var i,u,a=8*o-n-1,f=(1<>1,s=-7,l=e?o-1:0,h=e?-1:1,p=t[r+l];for(l+=h,i=p&(1<<-s)-1,p>>=-s,s+=a;s>0;i=256*i+t[r+l],l+=h,s-=8);for(u=i&(1<<-s)-1,i>>=-s,s+=n;s>0;u=256*u+t[r+l],l+=h,s-=8);if(0===i)i=1-c;else{if(i===f)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),i-=c}return(p?-1:1)*u*Math.pow(2,i-n)}function zn(t,r,e,n,o,i){var u,a,f,c=8*i-o-1,s=(1<>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,y=n?1:-1,v=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,u=s):(u=Math.floor(Math.log(r)/Math.LN2),r*(f=Math.pow(2,-u))<1&&(u--,f*=2),(r+=u+l>=1?h/f:h*Math.pow(2,1-l))*f>=2&&(u++,f/=2),u+l>=s?(a=0,u=s):u+l>=1?(a=(r*f-1)*Math.pow(2,o),u+=l):(a=r*Math.pow(2,l-1)*Math.pow(2,o),u=0));o>=8;t[e+p]=255&a,p+=y,a/=256,o-=8);for(u=u<0;t[e+p]=255&u,p+=y,u/=256,c-=8);t[e+p-y]|=128*v}var Gn={}.toString,Xn=Array.isArray||function(t){return"[object Array]"==Gn.call(t)};qn.TYPED_ARRAY_SUPPORT=void 0===ft.TYPED_ARRAY_SUPPORT||ft.TYPED_ARRAY_SUPPORT;var $n=Hn();function Hn(){return qn.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Wn(t,r){if(Hn()=Hn())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Hn().toString(16)+" bytes");return 0|t}function ro(t){return!(null==t||!t._isBuffer)}function eo(t,r){if(ro(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return So(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return Io(t).length;default:if(n)return So(t).length;r=(""+r).toLowerCase(),n=!0}}function no(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return bo(this,r,e);case"utf8":case"utf-8":return yo(this,r,e);case"ascii":return go(this,r,e);case"latin1":case"binary":return wo(this,r,e);case"base64":return po(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return mo(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function oo(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function io(t,r,e,n,o){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0){if(!o)return-1;e=0}if("string"==typeof r&&(r=qn.from(r,n)),ro(r))return 0===r.length?-1:uo(t,r,e,n,o);if("number"==typeof r)return r&=255,qn.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):uo(t,[r],e,n,o);throw new TypeError("val must be string, number or Buffer")}function uo(t,r,e,n,o){var i,u=1,a=t.length,f=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,a/=2,f/=2,e/=2}function c(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(o){var s=-1;for(i=e;ia&&(e=a-f),i=e;i>=0;i--){for(var l=!0,h=0;ho&&(n=o):n=o;var i=r.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var u=0;u>8,o=e%256,i.push(o),i.push(n);return i}(r,t.length-e),t,e,n)}function po(t,r,e){return 0===r&&e===t.length?kn(t):kn(t.slice(r,e))}function yo(t,r,e){e=Math.min(t.length,e);for(var n=[],o=r;o239?4:c>223?3:c>191?2:1;if(o+l<=e)switch(l){case 1:c<128&&(s=c);break;case 2:128==(192&(i=t[o+1]))&&(f=(31&c)<<6|63&i)>127&&(s=f);break;case 3:i=t[o+1],u=t[o+2],128==(192&i)&&128==(192&u)&&(f=(15&c)<<12|(63&i)<<6|63&u)>2047&&(f<55296||f>57343)&&(s=f);break;case 4:i=t[o+1],u=t[o+2],a=t[o+3],128==(192&i)&&128==(192&u)&&128==(192&a)&&(f=(15&c)<<18|(63&i)<<12|(63&u)<<6|63&a)>65535&&f<1114112&&(s=f)}null===s?(s=65533,l=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=l}return function(t){var r=t.length;if(r<=vo)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),""},qn.prototype.compare=function(t,r,e,n,o){if(!ro(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),r<0||e>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&r>=e)return 0;if(n>=o)return-1;if(r>=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),a=Math.min(i,u),f=this.slice(n,o),c=t.slice(r,e),s=0;so)&&(e=o),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return ao(this,t,r,e);case"utf8":case"utf-8":return fo(this,t,r,e);case"ascii":return co(this,t,r,e);case"latin1":case"binary":return so(this,t,r,e);case"base64":return lo(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ho(this,t,r,e);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},qn.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var vo=4096;function go(t,r,e){var n="";e=Math.min(t.length,e);for(var o=r;on)&&(e=n);for(var o="",i=r;ie)throw new RangeError("Trying to access beyond buffer length")}function Eo(t,r,e,n,o,i){if(!ro(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>o||rt.length)throw new RangeError("Index out of range")}function _o(t,r,e,n){r<0&&(r=65535+r+1);for(var o=0,i=Math.min(t.length-e,2);o>>8*(n?o:1-o)}function Oo(t,r,e,n){r<0&&(r=4294967295+r+1);for(var o=0,i=Math.min(t.length-e,4);o>>8*(n?o:3-o)&255}function Po(t,r,e,n,o,i){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function jo(t,r,e,n,o){return o||Po(t,0,e,4),zn(t,r,e,n,23,4),e+4}function Ro(t,r,e,n,o){return o||Po(t,0,e,8),zn(t,r,e,n,52,8),e+8}qn.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(o*=256);)n+=this[t+--r]*o;return n},qn.prototype.readUInt8=function(t,r){return r||Ao(t,1,this.length),this[t]},qn.prototype.readUInt16LE=function(t,r){return r||Ao(t,2,this.length),this[t]|this[t+1]<<8},qn.prototype.readUInt16BE=function(t,r){return r||Ao(t,2,this.length),this[t]<<8|this[t+1]},qn.prototype.readUInt32LE=function(t,r){return r||Ao(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},qn.prototype.readUInt32BE=function(t,r){return r||Ao(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},qn.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||Ao(t,r,this.length);for(var n=this[t],o=1,i=0;++i=(o*=128)&&(n-=Math.pow(2,8*r)),n},qn.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||Ao(t,r,this.length);for(var n=r,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*r)),i},qn.prototype.readInt8=function(t,r){return r||Ao(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},qn.prototype.readInt16LE=function(t,r){r||Ao(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},qn.prototype.readInt16BE=function(t,r){r||Ao(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},qn.prototype.readInt32LE=function(t,r){return r||Ao(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},qn.prototype.readInt32BE=function(t,r){return r||Ao(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},qn.prototype.readFloatLE=function(t,r){return r||Ao(t,4,this.length),Vn(this,t,!0,23,4)},qn.prototype.readFloatBE=function(t,r){return r||Ao(t,4,this.length),Vn(this,t,!1,23,4)},qn.prototype.readDoubleLE=function(t,r){return r||Ao(t,8,this.length),Vn(this,t,!0,52,8)},qn.prototype.readDoubleBE=function(t,r){return r||Ao(t,8,this.length),Vn(this,t,!1,52,8)},qn.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||Eo(this,t,r,e,Math.pow(2,8*e)-1,0);var o=1,i=0;for(this[r]=255&t;++i=0&&(i*=256);)this[r+o]=t/i&255;return r+e},qn.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,1,255,0),qn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},qn.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,65535,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):_o(this,t,r,!0),r+2},qn.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,65535,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):_o(this,t,r,!1),r+2},qn.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,4294967295,0),qn.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):Oo(this,t,r,!0),r+4},qn.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,4294967295,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Oo(this,t,r,!1),r+4},qn.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Eo(this,t,r,e,o-1,-o)}var i=0,u=1,a=0;for(this[r]=255&t;++i>0)-a&255;return r+e},qn.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Eo(this,t,r,e,o-1,-o)}var i=e-1,u=1,a=0;for(this[r+i]=255&t;--i>=0&&(u*=256);)t<0&&0===a&&0!==this[r+i+1]&&(a=1),this[r+i]=(t/u>>0)-a&255;return r+e},qn.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,1,127,-128),qn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},qn.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,32767,-32768),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):_o(this,t,r,!0),r+2},qn.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,32767,-32768),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):_o(this,t,r,!1),r+2},qn.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,2147483647,-2147483648),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):Oo(this,t,r,!0),r+4},qn.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Oo(this,t,r,!1),r+4},qn.prototype.writeFloatLE=function(t,r,e){return jo(this,t,r,!0,e)},qn.prototype.writeFloatBE=function(t,r,e){return jo(this,t,r,!1,e)},qn.prototype.writeDoubleLE=function(t,r,e){return Ro(this,t,r,!0,e)},qn.prototype.writeDoubleBE=function(t,r,e){return Ro(this,t,r,!1,e)},qn.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--o)t[o+r]=this[o+e];else if(i<1e3||!qn.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(i=r;i55295&&e<57344){if(!o){if(e>56319){(r-=3)>-1&&i.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&i.push(239,191,189);continue}o=e;continue}if(e<56320){(r-=3)>-1&&i.push(239,191,189),o=e;continue}e=65536+(o-55296<<10|e-56320)}else o&&(r-=3)>-1&&i.push(239,191,189);if(o=null,e<128){if((r-=1)<0)break;i.push(e)}else if(e<2048){if((r-=2)<0)break;i.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;i.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;i.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return i}function Io(t){return function(t){var r,e,n,o,i,u;Fn||Dn();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[a-2]?2:"="===t[a-1]?1:0,u=new Ln(3*a/4-i),n=i>0?a-4:a;var f=0;for(r=0,e=0;r>16&255,u[f++]=o>>8&255,u[f++]=255&o;return 2===i?(o=Mn[t.charCodeAt(r)]<<2|Mn[t.charCodeAt(r+1)]>>4,u[f++]=255&o):1===i&&(o=Mn[t.charCodeAt(r)]<<10|Mn[t.charCodeAt(r+1)]<<4|Mn[t.charCodeAt(r+2)]>>2,u[f++]=o>>8&255,u[f++]=255&o),u}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(To,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Bo(t,r,e,n){for(var o=0;o=r.length||o>=t.length);++o)r[o+e]=t[o];return o}function Yo(t){return null!=t&&(!!t._isBuffer||xo(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&xo(t.slice(0,0))}(t))}function xo(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var Co=t(Object.freeze({__proto__:null,Buffer:qn,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),qn.alloc(+t)},isBuffer:Yo,kMaxLength:$n})).Buffer,Mo=function(){throw new Error("not implemented")},Lo=xn()?Co:Mo,Fo=zt(Lo.from),Do=Bt,No=Lo;var ko=function(t){if(!Do(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return No.from(t)},Vo=Bt,zo=Lo;var Go=function(t){if(!Vo(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return new zo(t)},Xo=Fo?ko:Go,$o=I,Ho="function"==typeof Int8Array;var Wo="function"==typeof Int8Array?Int8Array:null,qo=function(t){return Ho&&t instanceof Int8Array||"[object Int8Array]"===$o(t)},Jo=Wo;var Zo=function(){var t,r;if("function"!=typeof Jo)return!1;try{r=new Jo([1,3.14,-3.14,128]),t=qo(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-128===r[3]}catch(r){t=!1}return t};var Ko="function"==typeof Int8Array?Int8Array:void 0,Qo=function(){throw new Error("not implemented")},ti=Zo()?Ko:Qo,ri=I,ei="function"==typeof Uint8Array;var ni="function"==typeof Uint8Array?Uint8Array:null,oi=function(t){return ei&&t instanceof Uint8Array||"[object Uint8Array]"===ri(t)},ii=ni;var ui=function(){var t,r;if("function"!=typeof ii)return!1;try{r=new ii(r=[1,3.14,-3.14,256,257]),t=oi(r)&&1===r[0]&&3===r[1]&&253===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var ai="function"==typeof Uint8Array?Uint8Array:void 0,fi=function(){throw new Error("not implemented")},ci=ui()?ai:fi,si=I,li="function"==typeof Uint8ClampedArray;var hi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:null,pi=function(t){return li&&t instanceof Uint8ClampedArray||"[object Uint8ClampedArray]"===si(t)},yi=hi;var vi=function(){var t,r;if("function"!=typeof yi)return!1;try{r=new yi([-1,0,1,3.14,4.99,255,256]),t=pi(r)&&0===r[0]&&0===r[1]&&1===r[2]&&3===r[3]&&5===r[4]&&255===r[5]&&255===r[6]}catch(r){t=!1}return t};var gi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:void 0,wi=function(){throw new Error("not implemented")},di=vi()?gi:wi,bi=I,mi="function"==typeof Int16Array;var Ai="function"==typeof Int16Array?Int16Array:null,Ei=function(t){return mi&&t instanceof Int16Array||"[object Int16Array]"===bi(t)},_i=Ai;var Oi=function(){var t,r;if("function"!=typeof _i)return!1;try{r=new _i([1,3.14,-3.14,32768]),t=Ei(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-32768===r[3]}catch(r){t=!1}return t};var Pi="function"==typeof Int16Array?Int16Array:void 0,ji=function(){throw new Error("not implemented")},Ri=Oi()?Pi:ji,Ti=I,Ui="function"==typeof Uint16Array;var Si="function"==typeof Uint16Array?Uint16Array:null,Ii=function(t){return Ui&&t instanceof Uint16Array||"[object Uint16Array]"===Ti(t)},Bi=Si;var Yi=function(){var t,r;if("function"!=typeof Bi)return!1;try{r=new Bi(r=[1,3.14,-3.14,65536,65537]),t=Ii(r)&&1===r[0]&&3===r[1]&&65533===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var xi="function"==typeof Uint16Array?Uint16Array:void 0,Ci=function(){throw new Error("not implemented")},Mi=Yi()?xi:Ci,Li=I,Fi="function"==typeof Int32Array;var Di="function"==typeof Int32Array?Int32Array:null,Ni=function(t){return Fi&&t instanceof Int32Array||"[object Int32Array]"===Li(t)},ki=Di;var Vi=function(){var t,r;if("function"!=typeof ki)return!1;try{r=new ki([1,3.14,-3.14,2147483648]),t=Ni(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-2147483648===r[3]}catch(r){t=!1}return t};var zi="function"==typeof Int32Array?Int32Array:void 0,Gi=function(){throw new Error("not implemented")},Xi=Vi()?zi:Gi,$i=I,Hi="function"==typeof Uint32Array;var Wi="function"==typeof Uint32Array?Uint32Array:null,qi=function(t){return Hi&&t instanceof Uint32Array||"[object Uint32Array]"===$i(t)},Ji=Wi;var Zi=function(){var t,r;if("function"!=typeof Ji)return!1;try{r=new Ji(r=[1,3.14,-3.14,4294967296,4294967297]),t=qi(r)&&1===r[0]&&3===r[1]&&4294967293===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var Ki="function"==typeof Uint32Array?Uint32Array:void 0,Qi=function(){throw new Error("not implemented")},tu=Zi()?Ki:Qi,ru=I,eu="function"==typeof Float32Array;var nu="function"==typeof Float32Array?Float32Array:null,ou=function(t){return eu&&t instanceof Float32Array||"[object Float32Array]"===ru(t)},iu=pr,uu=nu;var au=function(){var t,r;if("function"!=typeof uu)return!1;try{r=new uu([1,3.14,-3.14,5e40]),t=ou(r)&&1===r[0]&&3.140000104904175===r[1]&&-3.140000104904175===r[2]&&r[3]===iu}catch(r){t=!1}return t};var fu="function"==typeof Float32Array?Float32Array:void 0,cu=function(){throw new Error("not implemented")},su=au()?fu:cu,lu=I,hu="function"==typeof Float64Array;var pu="function"==typeof Float64Array?Float64Array:null,yu=function(t){return hu&&t instanceof Float64Array||"[object Float64Array]"===lu(t)},vu=pu;var gu=function(){var t,r;if("function"!=typeof vu)return!1;try{r=new vu([1,3.14,-3.14,NaN]),t=yu(r)&&1===r[0]&&3.14===r[1]&&-3.14===r[2]&&r[3]!=r[3]}catch(r){t=!1}return t};var wu,du="function"==typeof Float64Array?Float64Array:void 0,bu=function(){throw new Error("not implemented")};wu=gu()?du:bu;var mu=ti,Au=ci,Eu=di,_u=Ri,Ou=Mi,Pu=Xi,ju=tu,Ru=su,Tu=wu;function Uu(t){return new mu(t)}function Su(t){return new Au(t)}function Iu(t){return new Eu(t)}function Bu(t){return new _u(t)}function Yu(t){return new Ou(t)}function xu(t){return new Pu(t)}function Cu(t){return new ju(t)}function Mu(t){return new Ru(t)}function Lu(t){return new Tu(t)}var Fu=O,Du=Rt,Nu=Bt,ku=te,Vu=kt,zu=ie,Gu=Pe,Xu=Pn,$u=Un,Hu=Yn,Wu=Zr,qu=p,Ju=Xo,Zu={int8array:Uu,uint8array:Su,uint8clampedarray:Iu,int16array:Bu,uint16array:Yu,int32array:xu,uint32array:Cu,float32array:Mu,float64array:Lu};function Ku(t,r,e,n,o){var i,u,a,f,c,s,l,h,p,y;if(o-=1,"object"!=typeof t||null===t)return t;if(Nu(t))return Ju(t);if(ku(t))return function(t){var r,e,n,o,i,u,a=[],f=[];for(i=new t.constructor(t.message),a.push(t),f.push(i),t.stack&&(i.stack=t.stack),t.code&&(i.code=t.code),t.errno&&(i.errno=t.errno),t.syscall&&(i.syscall=t.syscall),r=Xu(t),u=0;u0)for(i=a,y=0;y1){if(!ta(r))throw new TypeError("invalid argument. `level` must be a nonnegative integer. Value: `"+r+"`.");if(0===r)return t}else r=ra;return e=Qu(t)?new Array(t.length):{},ea(t,e,[t],[e],r)},oa=na,ia=Rt;var ua=function(t){return"object"==typeof t&&null!==t&&!ia(t)},aa=zt,fa=Zr,ca=O,sa=I,la=Object.prototype;var ha=function(t){var r;return!!ua(t)&&(!(r=fa(t))||!ca(t,"constructor")&&ca(r,"constructor")&&aa(r.constructor)&&"[object Function]"===sa(r.constructor)&&ca(r,"isPrototypeOf")&&aa(r.isPrototypeOf)&&(r===la||function(t){var r;for(r in t)if(!ca(t,r))return!1;return!0}(t)))},pa=ha,ya=O,va=V.isPrimitive;var ga={url:"https://stdlib.io/docs/api/latest/error-decoder.html",message:"Minified stdlib error code: {{code}}. Visit {{url}} for the full message."},wa=Kt,da=oa,ba=function(t,r){return pa(r)?ya(r,"url")&&(t.url=r.url,!va(t.url))?new TypeError("invalid option. `url` option must be a string primitive. Option: `"+t.url+"`."):ya(r,"message")&&(t.message=r.message,!va(t.message))?new TypeError("invalid option. `message` option must be a string primitive. Option: `"+t.message+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.")},ma=ga;var Aa=function(t){var r,e;if(r=da(ma),e=ba(r,t))throw e;return function(){var t,e,n=arguments[0],o=r.url+"?code="+n;for(e=1;e=f&&(s=f-1);else if("wrap"===u)s<0?(s+=f)<0&&0!==(s%=f)&&(s+=f):s>=f&&(s-=f)>=f&&(s%=f);else if(s<0||s>=f)throw new RangeError(_a("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",l,s));(c=t[l])<0&&0===r?a-=s*c:a+=s*c}return a}})); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 75b90f6..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/utils-define-property/lib/define_property.js","../node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js","../node_modules/@stdlib/utils-define-property/lib/builtin.js","../node_modules/@stdlib/utils-define-property/lib/polyfill.js","../node_modules/@stdlib/utils-define-property/lib/index.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/primitive.js","../node_modules/@stdlib/assert-has-symbol-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostring.js","../node_modules/@stdlib/utils-native-class/lib/native_class.js","../node_modules/@stdlib/assert-has-own-property/lib/main.js","../node_modules/@stdlib/assert-has-own-property/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostringtag.js","../node_modules/@stdlib/utils-native-class/lib/polyfill.js","../node_modules/@stdlib/utils-native-class/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/try2valueof.js","../node_modules/@stdlib/assert-is-string/lib/valueof.js","../node_modules/@stdlib/assert-is-string/lib/object.js","../node_modules/@stdlib/assert-is-string/lib/main.js","../node_modules/@stdlib/assert-is-string/lib/index.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/main.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/re.js","../node_modules/@stdlib/assert-is-boolean/lib/primitive.js","../node_modules/@stdlib/assert-is-boolean/lib/try2serialize.js","../node_modules/@stdlib/assert-is-boolean/lib/tostring.js","../node_modules/@stdlib/assert-is-boolean/lib/object.js","../node_modules/@stdlib/assert-is-boolean/lib/main.js","../node_modules/@stdlib/assert-is-boolean/lib/index.js","../node_modules/@stdlib/utils-global/lib/codegen.js","../node_modules/@stdlib/utils-global/lib/self.js","../node_modules/@stdlib/utils-global/lib/window.js","../node_modules/@stdlib/utils-global/lib/global.js","../node_modules/@stdlib/utils-global/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/nodelist.js","../node_modules/@stdlib/utils-global/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/typedarray.js","../node_modules/@stdlib/utils-type-of/lib/check.js","../node_modules/@stdlib/regexp-function-name/lib/main.js","../node_modules/@stdlib/regexp-function-name/lib/index.js","../node_modules/@stdlib/regexp-function-name/lib/regexp.js","../node_modules/@stdlib/assert-is-array/lib/main.js","../node_modules/@stdlib/assert-is-array/lib/index.js","../node_modules/@stdlib/assert-tools-array-function/lib/arrayfcn.js","../node_modules/@stdlib/assert-is-object-like/lib/main.js","../node_modules/@stdlib/assert-is-object-like/lib/index.js","../node_modules/@stdlib/assert-is-buffer/lib/main.js","../node_modules/@stdlib/assert-is-buffer/lib/index.js","../node_modules/@stdlib/utils-constructor-name/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/typeof.js","../node_modules/@stdlib/utils-constructor-name/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/polyfill.js","../node_modules/@stdlib/utils-type-of/lib/index.js","../node_modules/@stdlib/assert-is-function/lib/main.js","../node_modules/@stdlib/assert-is-function/lib/index.js","../node_modules/@stdlib/assert-is-regexp/lib/try2exec.js","../node_modules/@stdlib/assert-is-regexp/lib/exec.js","../node_modules/@stdlib/assert-is-regexp/lib/main.js","../node_modules/@stdlib/string-replace/lib/replace.js","../node_modules/@stdlib/string-replace/lib/index.js","../node_modules/@stdlib/assert-is-number/lib/primitive.js","../node_modules/@stdlib/number-ctor/lib/index.js","../node_modules/@stdlib/number-ctor/lib/number.js","../node_modules/@stdlib/assert-is-number/lib/try2serialize.js","../node_modules/@stdlib/assert-is-number/lib/tostring.js","../node_modules/@stdlib/assert-is-number/lib/object.js","../node_modules/@stdlib/assert-is-number/lib/main.js","../node_modules/@stdlib/assert-is-number/lib/index.js","../node_modules/@stdlib/constants-float64-pinf/lib/index.js","../node_modules/@stdlib/constants-float64-ninf/lib/index.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/is_integer.js","../node_modules/@stdlib/math-base-special-floor/lib/main.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-integer/lib/integer.js","../node_modules/@stdlib/assert-is-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-integer/lib/object.js","../node_modules/@stdlib/assert-is-integer/lib/main.js","../node_modules/@stdlib/assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/object.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/main.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/index.js","../node_modules/@stdlib/utils-get-prototype-of/lib/native.js","../node_modules/@stdlib/utils-get-prototype-of/lib/proto.js","../node_modules/@stdlib/utils-get-prototype-of/lib/polyfill.js","../node_modules/@stdlib/utils-get-prototype-of/lib/detect.js","../node_modules/@stdlib/utils-get-prototype-of/lib/get_prototype_of.js","../node_modules/@stdlib/utils-get-prototype-of/lib/index.js","../node_modules/@stdlib/assert-is-error/lib/main.js","../node_modules/@stdlib/assert-is-error/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/main.js","../node_modules/@stdlib/regexp-regexp/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/regexp.js","../node_modules/@stdlib/utils-regexp-from-string/lib/from_string.js","../node_modules/@stdlib/utils-regexp-from-string/lib/index.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/primitive.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-nan/lib/object.js","../node_modules/@stdlib/assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-collection/lib/main.js","../node_modules/@stdlib/utils-index-of/lib/index_of.js","../node_modules/@stdlib/constants-array-max-typed-array-length/lib/index.js","../node_modules/@stdlib/utils-index-of/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin.js","../node_modules/@stdlib/utils-keys/lib/has_arguments_bug.js","../node_modules/@stdlib/utils-keys/lib/has_builtin.js","../node_modules/@stdlib/assert-is-arguments/lib/main.js","../node_modules/@stdlib/assert-is-arguments/lib/detect.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/has_string_enumerability_bug.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/native.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/main.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/index.js","../node_modules/@stdlib/assert-is-arguments/lib/polyfill.js","../node_modules/@stdlib/assert-is-arguments/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin_wrapper.js","../node_modules/@stdlib/utils-noop/lib/noop.js","../node_modules/@stdlib/utils-keys/lib/has_enumerable_prototype_bug.js","../node_modules/@stdlib/utils-keys/lib/has_non_enumerable_properties_bug.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype.js","../node_modules/@stdlib/utils-keys/lib/has_automation_equality_bug.js","../node_modules/@stdlib/utils-keys/lib/window.js","../node_modules/@stdlib/utils-keys/lib/has_window.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype_wrapper.js","../node_modules/@stdlib/utils-keys/lib/polyfill.js","../node_modules/@stdlib/utils-keys/lib/main.js","../node_modules/@stdlib/utils-keys/lib/index.js","../node_modules/@stdlib/utils-property-names/lib/has_builtin.js","../node_modules/@stdlib/utils-property-names/lib/builtin.js","../node_modules/@stdlib/utils-property-names/lib/polyfill.js","../node_modules/@stdlib/utils-property-names/lib/index.js","../node_modules/@stdlib/utils-property-descriptor/lib/has_builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/polyfill.js","../node_modules/@stdlib/utils-property-descriptor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/polyfill.js","../node_modules/@stdlib/buffer-ctor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/buffer.js","../node_modules/@stdlib/buffer-from-buffer/lib/has_from.js","../node_modules/@stdlib/buffer-from-buffer/lib/main.js","../node_modules/@stdlib/buffer-from-buffer/lib/polyfill.js","../node_modules/@stdlib/buffer-from-buffer/lib/index.js","../node_modules/@stdlib/assert-is-int8array/lib/main.js","../node_modules/@stdlib/assert-has-int8array-support/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/main.js","../node_modules/@stdlib/constants-int8-min/lib/index.js","../node_modules/@stdlib/array-int8/lib/polyfill.js","../node_modules/@stdlib/array-int8/lib/index.js","../node_modules/@stdlib/array-int8/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8array/lib/main.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/main.js","../node_modules/@stdlib/array-uint8/lib/polyfill.js","../node_modules/@stdlib/array-uint8/lib/index.js","../node_modules/@stdlib/array-uint8/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8clampedarray/lib/main.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/main.js","../node_modules/@stdlib/array-uint8c/lib/polyfill.js","../node_modules/@stdlib/array-uint8c/lib/index.js","../node_modules/@stdlib/array-uint8c/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/index.js","../node_modules/@stdlib/assert-is-int16array/lib/main.js","../node_modules/@stdlib/assert-has-int16array-support/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/main.js","../node_modules/@stdlib/constants-int16-min/lib/index.js","../node_modules/@stdlib/array-int16/lib/polyfill.js","../node_modules/@stdlib/array-int16/lib/index.js","../node_modules/@stdlib/array-int16/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint16array/lib/main.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/main.js","../node_modules/@stdlib/array-uint16/lib/polyfill.js","../node_modules/@stdlib/array-uint16/lib/index.js","../node_modules/@stdlib/array-uint16/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/index.js","../node_modules/@stdlib/assert-is-int32array/lib/main.js","../node_modules/@stdlib/assert-has-int32array-support/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/main.js","../node_modules/@stdlib/constants-int32-min/lib/index.js","../node_modules/@stdlib/array-int32/lib/polyfill.js","../node_modules/@stdlib/array-int32/lib/index.js","../node_modules/@stdlib/array-int32/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint32array/lib/main.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/main.js","../node_modules/@stdlib/array-uint32/lib/polyfill.js","../node_modules/@stdlib/array-uint32/lib/index.js","../node_modules/@stdlib/array-uint32/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float32array/lib/main.js","../node_modules/@stdlib/assert-has-float32array-support/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/main.js","../node_modules/@stdlib/array-float32/lib/polyfill.js","../node_modules/@stdlib/array-float32/lib/index.js","../node_modules/@stdlib/array-float32/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float64array/lib/main.js","../node_modules/@stdlib/assert-has-float64array-support/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/main.js","../node_modules/@stdlib/array-float64/lib/polyfill.js","../node_modules/@stdlib/array-float64/lib/index.js","../node_modules/@stdlib/array-float64/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/index.js","../node_modules/@stdlib/utils-copy/lib/typed_arrays.js","../node_modules/@stdlib/utils-copy/lib/deep_copy.js","../node_modules/@stdlib/utils-copy/lib/copy.js","../node_modules/@stdlib/utils-copy/lib/index.js","../node_modules/@stdlib/assert-is-object/lib/main.js","../node_modules/@stdlib/assert-is-plain-object/lib/main.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/validate.js","../node_modules/@stdlib/assert-is-plain-object/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/factory.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\nvar main = ( typeof Object.defineProperty === 'function' ) ? Object.defineProperty : null;\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar defineProperty = require( './define_property.js' );\n\n\n// MAIN //\n\n/**\n* Tests for `Object.defineProperty` support.\n*\n* @private\n* @returns {boolean} boolean indicating if an environment has `Object.defineProperty` support\n*\n* @example\n* var bool = hasDefinePropertySupport();\n* // returns \n*/\nfunction hasDefinePropertySupport() {\n\t// Test basic support...\n\ttry {\n\t\tdefineProperty( {}, 'x', {} );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasDefinePropertySupport;\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// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @name defineProperty\n* @type {Function}\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nvar defineProperty = Object.defineProperty;\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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/* eslint-disable no-underscore-dangle, no-proto */\n\n'use strict';\n\n// VARIABLES //\n\nvar objectProtoype = Object.prototype;\nvar toStr = objectProtoype.toString;\nvar defineGetter = objectProtoype.__defineGetter__;\nvar defineSetter = objectProtoype.__defineSetter__;\nvar lookupGetter = objectProtoype.__lookupGetter__;\nvar lookupSetter = objectProtoype.__lookupSetter__;\n\n\n// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @param {Object} obj - object on which to define the property\n* @param {string} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nfunction defineProperty( obj, prop, descriptor ) {\n\tvar prototype;\n\tvar hasValue;\n\tvar hasGet;\n\tvar hasSet;\n\n\tif ( typeof obj !== 'object' || obj === null || toStr.call( obj ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an object. Value: `' + obj + '`.' );\n\t}\n\tif ( typeof descriptor !== 'object' || descriptor === null || toStr.call( descriptor ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. Property descriptor must be an object. Value: `' + descriptor + '`.' );\n\t}\n\thasValue = ( 'value' in descriptor );\n\tif ( hasValue ) {\n\t\tif (\n\t\t\tlookupGetter.call( obj, prop ) ||\n\t\t\tlookupSetter.call( obj, prop )\n\t\t) {\n\t\t\t// Override `__proto__` to avoid touching inherited accessors:\n\t\t\tprototype = obj.__proto__;\n\t\t\tobj.__proto__ = objectProtoype;\n\n\t\t\t// Delete property as existing getters/setters prevent assigning value to specified property:\n\t\t\tdelete obj[ prop ];\n\t\t\tobj[ prop ] = descriptor.value;\n\n\t\t\t// Restore original prototype:\n\t\t\tobj.__proto__ = prototype;\n\t\t} else {\n\t\t\tobj[ prop ] = descriptor.value;\n\t\t}\n\t}\n\thasGet = ( 'get' in descriptor );\n\thasSet = ( 'set' in descriptor );\n\n\tif ( hasValue && ( hasGet || hasSet ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.' );\n\t}\n\n\tif ( hasGet && defineGetter ) {\n\t\tdefineGetter.call( obj, prop, descriptor.get );\n\t}\n\tif ( hasSet && defineSetter ) {\n\t\tdefineSetter.call( obj, prop, descriptor.set );\n\t}\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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* Define (or modify) an object property.\n*\n* @module @stdlib/utils-define-property\n*\n* @example\n* var defineProperty = require( '@stdlib/utils-define-property' );\n*\n* var obj = {};\n* defineProperty( obj, 'foo', {\n* 'value': 'bar',\n* 'writable': false,\n* 'configurable': false,\n* 'enumerable': false\n* });\n* obj.foo = 'boop'; // => throws\n*/\n\n// MODULES //\n\nvar hasDefinePropertySupport = require( './has_define_property_support.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar defineProperty;\nif ( hasDefinePropertySupport() ) {\n\tdefineProperty = builtin;\n} else {\n\tdefineProperty = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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\nvar defineProperty = require( '@stdlib/utils-define-property' );\n\n\n// MAIN //\n\n/**\n* Defines a non-enumerable read-only property.\n*\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setNonEnumerableReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Define a non-enumerable read-only property.\n*\n* @module @stdlib/utils-define-nonenumerable-read-only-property\n*\n* @example\n* var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\n*\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\n\n// MODULES //\n\nvar setNonEnumerableReadOnly = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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// MAIN //\n\n/**\n* Tests for native `Symbol` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Symbol` support\n*\n* @example\n* var bool = hasSymbolSupport();\n* // returns \n*/\nfunction hasSymbolSupport() {\n\treturn (\n\t\ttypeof Symbol === 'function' &&\n\t\ttypeof Symbol( 'foo' ) === 'symbol'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasSymbolSupport;\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\nvar hasSymbols = require( '@stdlib/assert-has-symbol-support' );\n\n\n// VARIABLES //\n\nvar FLG = hasSymbols();\n\n\n// MAIN //\n\n/**\n* Tests for native `toStringTag` support.\n*\n* @returns {boolean} boolean indicating if an environment has `toStringTag` support\n*\n* @example\n* var bool = hasToStringTagSupport();\n* // returns \n*/\nfunction hasToStringTagSupport() {\n\treturn ( FLG && typeof Symbol.toStringTag === 'symbol' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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* Test for native `toStringTag` support.\n*\n* @module @stdlib/assert-has-tostringtag-support\n*\n* @example\n* var hasToStringTagSupport = require( '@stdlib/assert-has-tostringtag-support' );\n*\n* var bool = hasToStringTagSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasToStringTagSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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// MAIN //\n\nvar toStr = Object.prototype.toString;\n\n\n// EXPORTS //\n\nmodule.exports = toStr;\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\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification (via the internal property `[[Class]]`) of an object.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\treturn toStr.call( v );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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// FUNCTIONS //\n\nvar has = Object.prototype.hasOwnProperty;\n\n\n// MAIN //\n\n/**\n* Tests if an object has a specified property.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object has a specified property\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'bap' );\n* // returns false\n*/\nfunction hasOwnProp( value, property ) {\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\treturn has.call( value, property );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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* Test whether an object has a specified property.\n*\n* @module @stdlib/assert-has-own-property\n*\n* @example\n* var hasOwnProp = require( '@stdlib/assert-has-own-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* bool = hasOwnProp( beep, 'bop' );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasOwnProp = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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// MAIN //\n\nvar toStrTag = ( typeof Symbol === 'function' ) ? Symbol.toStringTag : '';\n\n\n// EXPORTS //\n\nmodule.exports = toStrTag;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar toStringTag = require( './tostringtag.js' );\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification of an object in environments supporting `Symbol.toStringTag`.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\tvar isOwn;\n\tvar tag;\n\tvar out;\n\n\tif ( v === null || v === void 0 ) {\n\t\treturn toStr.call( v );\n\t}\n\ttag = v[ toStringTag ];\n\tisOwn = hasOwnProp( v, toStringTag );\n\n\t// Attempt to override the `toStringTag` property. For built-ins having a `Symbol.toStringTag` property (e.g., `JSON`, `Math`, etc), the `Symbol.toStringTag` property is read-only (e.g., , so we need to wrap in a `try/catch`.\n\ttry {\n\t\tv[ toStringTag ] = void 0;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn toStr.call( v );\n\t}\n\tout = toStr.call( v );\n\n\tif ( isOwn ) {\n\t\tv[ toStringTag ] = tag;\n\t} else {\n\t\tdelete v[ toStringTag ];\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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* Return a string value indicating a specification defined classification of an object.\n*\n* @module @stdlib/utils-native-class\n*\n* @example\n* var nativeClass = require( '@stdlib/utils-native-class' );\n*\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* function Beep() {\n* return this;\n* }\n* str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\n\n// MODULES //\n\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar builtin = require( './native_class.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar nativeClass;\nif ( hasToStringTag() ) {\n\tnativeClass = polyfill;\n} else {\n\tnativeClass = builtin;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to extract a string value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a string can be extracted\n*/\nfunction test( value ) {\n\ttry {\n\t\tvalueOf.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar valueOf = String.prototype.valueOf; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2valueof.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string object\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns false\n*/\nfunction isString( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof String ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object String]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a string\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*/\nfunction isString( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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* Test if a value is a string.\n*\n* @module @stdlib/assert-is-string\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' );\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 5 );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isObject;\n*\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 'beep' );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isString = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isString, 'isPrimitive', isPrimitive );\nsetReadOnly( isString, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// VARIABLES //\n\nvar RE_CHARS = /[-\\/\\\\^$*+?.()|[\\]{}]/g; // eslint-disable-line no-useless-escape\n\n\n// MAIN //\n\n/**\n* Escapes a regular expression string.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} first argument must be a string primitive\n* @returns {string} escaped string\n*\n* @example\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\nfunction rescape( str ) {\n\tvar len;\n\tvar s;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Check if the string starts with a forward slash...\n\tif ( str[ 0 ] === '/' ) {\n\t\t// Find the last forward slash...\n\t\tlen = str.length;\n\t\tfor ( i = len-1; i >= 0; i-- ) {\n\t\t\tif ( str[ i ] === '/' ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:\n\tif ( i === void 0 || i <= 0 ) {\n\t\treturn str.replace( RE_CHARS, '\\\\$&' );\n\t}\n\t// We need to de-construct the string...\n\ts = str.substring( 1, i );\n\n\t// Only escape the characters between the `/`:\n\ts = s.replace( RE_CHARS, '\\\\$&' );\n\n\t// Reassemble:\n\tstr = str[ 0 ] + s + str.substring( i );\n\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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* Escape a regular expression string or pattern.\n*\n* @module @stdlib/utils-escape-regexp-string\n*\n* @example\n* var rescape = require( '@stdlib/utils-escape-regexp-string' );\n*\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\n\n// MODULES //\n\nvar rescape = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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\nvar RE = /./;\n\n\n// EXPORTS //\n\nmodule.exports = RE;\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* Tests if a value is a boolean primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean primitive\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns false\n*/\nfunction isBoolean( value ) {\n\treturn ( typeof value === 'boolean' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Boolean.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean object\n*\n* @example\n* var bool = isBoolean( true );\n* // returns false\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Boolean ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Boolean]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a boolean\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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* Test if a value is a boolean.\n*\n* @module @stdlib/assert-is-boolean\n*\n* @example\n* var isBoolean = require( '@stdlib/assert-is-boolean' );\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* // Use interface to check for boolean primitives...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( true ) );\n* // returns false\n*\n* @example\n* // Use interface to check for boolean objects...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isObject;\n*\n* var bool = isBoolean( true );\n* // returns false\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isBoolean = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isBoolean, 'isPrimitive', isPrimitive );\nsetReadOnly( isBoolean, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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// MAIN //\n\n/**\n* Returns the global object using code generation.\n*\n* @private\n* @returns {Object} global object\n*/\nfunction getGlobal() {\n\treturn new Function( 'return this;' )(); // eslint-disable-line no-new-func\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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// MAIN //\n\nvar obj = ( typeof self === 'object' ) ? self : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof window === 'object' ) ? window : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof global === 'object' ) ? global : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar getThis = require( './codegen.js' );\nvar Self = require( './self.js' );\nvar Win = require( './window.js' );\nvar Global = require( './global.js' );\n\n\n// MAIN //\n\n/**\n* Returns the global object.\n*\n* ## Notes\n*\n* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.\n*\n* @param {boolean} [codegen=false] - boolean indicating whether to use code generation to resolve the global object\n* @throws {TypeError} must provide a boolean\n* @throws {Error} unable to resolve global object\n* @returns {Object} global object\n*\n* @example\n* var g = getGlobal();\n* // returns {...}\n*/\nfunction getGlobal( codegen ) {\n\tif ( arguments.length ) {\n\t\tif ( !isBoolean( codegen ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Must provide a boolean primitive. Value: `'+codegen+'`.' );\n\t\t}\n\t\tif ( codegen ) {\n\t\t\treturn getThis();\n\t\t}\n\t\t// Fall through...\n\t}\n\t// Case: browsers and web workers\n\tif ( Self ) {\n\t\treturn Self;\n\t}\n\t// Case: browsers\n\tif ( Win ) {\n\t\treturn Win;\n\t}\n\t// Case: Node.js\n\tif ( Global ) {\n\t\treturn Global;\n\t}\n\t// Case: unknown\n\tthrow new Error( 'unexpected error. Unable to resolve global object.' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar getGlobal = require( '@stdlib/utils-global' );\n\n\n// MAIN //\n\nvar root = getGlobal();\nvar nodeList = root.document && root.document.childNodes;\n\n\n// EXPORTS //\n\nmodule.exports = nodeList;\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* Return the global object.\n*\n* @module @stdlib/utils-global\n*\n* @example\n* var getGlobal = require( '@stdlib/utils-global' );\n*\n* var g = getGlobal();\n* // returns {...}\n*/\n\n// MODULES //\n\nvar getGlobal = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar typedarray = Int8Array; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = typedarray;\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\nvar RE = require( './fixtures/re.js' );\nvar nodeList = require( './fixtures/nodelist.js' );\nvar typedarray = require( './fixtures/typedarray.js' );\n\n\n// MAIN //\n\n/**\n* Checks whether a polyfill is needed when using the `typeof` operator.\n*\n* @private\n* @returns {boolean} boolean indicating whether a polyfill is needed\n*/\nfunction check() {\n\tif (\n\t\t// Chrome 1-12 returns 'function' for regular expression instances (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof):\n\t\ttypeof RE === 'function' ||\n\n\t\t// Safari 8 returns 'object' for typed array and weak map constructors (underscore #1929):\n\t\ttypeof typedarray === 'object' ||\n\n\t\t// PhantomJS 1.9 returns 'function' for `NodeList` instances (underscore #2236):\n\t\ttypeof nodeList === 'function'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\nfunction reFunctionName() {\n\treturn /^\\s*function\\s*([^(]*)/i;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @module @stdlib/regexp-function-name\n*\n* @example\n* var reFunctionName = require( '@stdlib/regexp-function-name' );\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reFunctionName = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reFunctionName, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\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\nvar reFunctionName = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Captures everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* Regular expression: `/^\\s*function\\s*([^(]*)/i`\n*\n* - `/^\\s*`\n* - Match zero or more spaces at beginning\n*\n* - `function`\n* - Match the word `function`\n*\n* - `\\s*`\n* - Match zero or more spaces after the word `function`\n*\n* - `()`\n* - Capture\n*\n* - `[^(]*`\n* - Match anything except a left parenthesis `(` zero or more times\n*\n* - `/i`\n* - ignore case\n*\n* @constant\n* @type {RegExp}\n* @default /^\\s*function\\s*([^(]*)/i\n*/\nvar RE_FUNCTION_NAME = reFunctionName();\n\n\n// EXPORTS //\n\nmodule.exports = RE_FUNCTION_NAME;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar f;\n\n\n// FUNCTIONS //\n\n/**\n* Tests if a value is an array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an array\n*\n* @example\n* var bool = isArray( [] );\n* // returns true\n*\n* @example\n* var bool = isArray( {} );\n* // returns false\n*/\nfunction isArray( value ) {\n\treturn ( nativeClass( value ) === '[object Array]' );\n}\n\n\n// MAIN //\n\nif ( Array.isArray ) {\n\tf = Array.isArray;\n} else {\n\tf = isArray;\n}\n\n\n// EXPORTS //\n\nmodule.exports = f;\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* Test if a value is an array.\n*\n* @module @stdlib/assert-is-array\n*\n* @example\n* var isArray = require( '@stdlib/assert-is-array' );\n*\n* var bool = isArray( [] );\n* // returns true\n*\n* bool = isArray( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isArray = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isArray;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Returns a function which tests if every element in an array passes a test condition.\n*\n* @param {Function} predicate - function to apply\n* @throws {TypeError} must provide a function\n* @returns {Function} an array function\n*\n* @example\n* var isOdd = require( '@stdlib/assert-is-odd' );\n*\n* var arr1 = [ 1, 3, 5, 7 ];\n* var arr2 = [ 3, 5, 8 ];\n*\n* var validate = arrayfcn( isOdd );\n*\n* var bool = validate( arr1 );\n* // returns true\n*\n* bool = validate( arr2 );\n* // returns false\n*/\nfunction arrayfcn( predicate ) {\n\tif ( typeof predicate !== 'function' ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a function. Value: `' + predicate + '`.' );\n\t}\n\treturn every;\n\n\t/**\n\t* Tests if every element in an array passes a test condition.\n\t*\n\t* @private\n\t* @param {*} value - value to test\n\t* @returns {boolean} boolean indicating whether a value is an array for which all elements pass a test condition\n\t*/\n\tfunction every( value ) {\n\t\tvar len;\n\t\tvar i;\n\t\tif ( !isArray( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tlen = value.length;\n\t\tif ( len === 0 ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( predicate( value[ i ] ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayfcn;\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* Tests if a value is object-like.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is object-like\n*\n* @example\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( [] );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( null );\n* // returns false\n*/\nfunction isObjectLike( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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* Test if a value is object-like.\n*\n* @module @stdlib/assert-is-object-like\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' );\n*\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* bool = isObjectLike( [] );\n* // returns true\n*\n* bool = isObjectLike( null );\n* // returns false\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' ).isObjectLikeArray;\n*\n* var bool = isObjectLike( [ {}, [] ] );\n* // returns true\n*\n* bool = isObjectLike( [ {}, '3.0' ] );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar arrayfun = require( '@stdlib/assert-tools-array-function' );\nvar isObjectLike = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( isObjectLike, 'isObjectLikeArray', arrayfun( isObjectLike ) );\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Buffer instance.\n*\n* @param {*} value - value to validate\n* @returns {boolean} boolean indicating if a value is a Buffer instance\n*\n* @example\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( new Buffer( [1,2,3,4] ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( {} );\n* // returns false\n*\n* @example\n* var v = isBuffer( [] );\n* // returns false\n*/\nfunction isBuffer( value ) {\n\treturn (\n\t\tisObjectLike( value ) &&\n\t\t(\n\t\t\t// eslint-disable-next-line no-underscore-dangle\n\t\t\tvalue._isBuffer || // for envs missing Object.prototype.constructor (e.g., Safari 5-7)\n\t\t\t(\n\t\t\t\tvalue.constructor &&\n\n\t\t\t\t// WARNING: `typeof` is not a foolproof check, as certain envs consider RegExp and NodeList instances to be functions\n\t\t\t\ttypeof value.constructor.isBuffer === 'function' &&\n\t\t\t\tvalue.constructor.isBuffer( value )\n\t\t\t)\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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* Test if a value is a Buffer instance.\n*\n* @module @stdlib/assert-is-buffer\n*\n* @example\n* var isBuffer = require( '@stdlib/assert-is-buffer' );\n*\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* v = isBuffer( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isBuffer = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar RE = require( '@stdlib/regexp-function-name' ).REGEXP;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\n\n\n// MAIN //\n\n/**\n* Determines the name of a value's constructor.\n*\n* @param {*} v - input value\n* @returns {string} name of a value's constructor\n*\n* @example\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* @example\n* var v = constructorName( 5 );\n* // returns 'Number'\n*\n* @example\n* var v = constructorName( null );\n* // returns 'Null'\n*\n* @example\n* var v = constructorName( undefined );\n* // returns 'Undefined'\n*\n* @example\n* var v = constructorName( function noop() {} );\n* // returns 'Function'\n*/\nfunction constructorName( v ) {\n\tvar match;\n\tvar name;\n\tvar ctor;\n\tname = nativeClass( v ).slice( 8, -1 );\n\tif ( (name === 'Object' || name === 'Error') && v.constructor ) {\n\t\tctor = v.constructor;\n\t\tif ( typeof ctor.name === 'string' ) {\n\t\t\treturn ctor.name;\n\t\t}\n\t\tmatch = RE.exec( ctor.toString() );\n\t\tif ( match ) {\n\t\t\treturn match[ 1 ];\n\t\t}\n\t}\n\tif ( isBuffer( v ) ) {\n\t\treturn 'Buffer';\n\t}\n\treturn name;\n}\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// NOTES //\n\n/*\n* Built-in `typeof` operator behavior:\n*\n* ```text\n* typeof null => 'object'\n* typeof undefined => 'undefined'\n* typeof 'a' => 'string'\n* typeof 5 => 'number'\n* typeof NaN => 'number'\n* typeof true => 'boolean'\n* typeof false => 'boolean'\n* typeof {} => 'object'\n* typeof [] => 'object'\n* typeof function foo(){} => 'function'\n* typeof function* foo(){} => 'object'\n* typeof Symbol() => 'symbol'\n* ```\n*\n*/\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\tvar type;\n\n\t// Address `typeof null` => `object` (see http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null):\n\tif ( v === null ) {\n\t\treturn 'null';\n\t}\n\ttype = typeof v;\n\n\t// If the `typeof` operator returned something other than `object`, we are done. Otherwise, we need to check for an internal class name or search for a constructor.\n\tif ( type === 'object' ) {\n\t\treturn ctorName( v ).toLowerCase();\n\t}\n\treturn type;\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine the name of a value's constructor.\n*\n* @module @stdlib/utils-constructor-name\n*\n* @example\n* var constructorName = require( '@stdlib/utils-constructor-name' );\n*\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* v = constructorName( {} );\n* // returns 'Object'\n*\n* v = constructorName( true );\n* // returns 'Boolean'\n*/\n\n// MODULES //\n\nvar constructorName = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\treturn ctorName( v ).toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine a value's type.\n*\n* @module @stdlib/utils-type-of\n*\n* @example\n* var typeOf = require( '@stdlib/utils-type-of' );\n*\n* var str = typeOf( 'a' );\n* // returns 'string'\n*\n* str = typeOf( 5 );\n* // returns 'number'\n*/\n\n// MODULES //\n\nvar usePolyfill = require( './check.js' );\nvar typeOf = require( './typeof.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main = ( usePolyfill() ) ? polyfill : typeOf;\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar typeOf = require( '@stdlib/utils-type-of' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a function.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a function\n*\n* @example\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\nfunction isFunction( value ) {\n\t// Note: cannot use `typeof` directly, as various browser engines incorrectly return `'function'` when operating on non-function objects, such as regular expressions and NodeLists.\n\treturn ( typeOf( value ) === 'function' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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* Test if a value is a function.\n*\n* @module @stdlib/assert-is-function\n*\n* @example\n* var isFunction = require( '@stdlib/assert-is-function' );\n*\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\n\n// MODULES //\n\nvar isFunction = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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\nvar exec = require( './exec.js' );\n\n\n// MAIN //\n\n/**\n* Attempts to call a `RegExp` method.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if able to call a `RegExp` method\n*/\nfunction test( value ) {\n\ttry {\n\t\texec.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar exec = RegExp.prototype.exec; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = exec;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2exec.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a regular expression.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a regular expression\n*\n* @example\n* var bool = isRegExp( /\\.+/ );\n* // returns true\n*\n* @example\n* var bool = isRegExp( {} );\n* // returns false\n*/\nfunction isRegExp( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof RegExp ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object RegExp]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isRegExp;\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\nvar rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument argument must be a string primitive or regular expression\n* @throws {TypeError} third argument must be a string primitive or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive or regular expression. Value: `' + search + '`.' );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( 'invalid argument. Third argument must be a string primitive or replacement function. Value: `' + newval + '`.' );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Constructor which returns a `Number` object.\n*\n* @module @stdlib/number-ctor\n*\n* @example\n* var Number = require( '@stdlib/number-ctor' );\n*\n* var v = new Number( 10.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar Number = require( './number.js' );\n\n\n// EXPORTS //\n\nmodule.exports = Number;\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// EXPORTS //\n\nmodule.exports = Number; // eslint-disable-line stdlib/require-globals\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Number.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar Number = require( '@stdlib/number-ctor' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\nfunction isNumber( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Number ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Number]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a number\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( null );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Test if a value is a number.\n*\n* @module @stdlib/assert-is-number\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' );\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( null );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isObject;\n*\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNumber, 'isPrimitive', isPrimitive );\nsetReadOnly( isNumber, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Double-precision floating-point positive infinity.\n*\n* @module @stdlib/constants-float64-pinf\n* @type {number}\n*\n* @example\n* var FLOAT64_PINF = require( '@stdlib/constants-float64-pinf' );\n* // returns Infinity\n*/\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point positive infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point positive infinity has the bit sequence\n*\n* ```binarystring\n* 0 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.POSITIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_PINF = Number.POSITIVE_INFINITY; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_PINF;\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* Double-precision floating-point negative infinity.\n*\n* @module @stdlib/constants-float64-ninf\n* @type {number}\n*\n* @example\n* var FLOAT64_NINF = require( '@stdlib/constants-float64-ninf' );\n* // returns -Infinity\n*/\n\n// MODULES //\n\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point negative infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point negative infinity has the bit sequence\n*\n* ```binarystring\n* 1 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.NEGATIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_NINF = Number.NEGATIVE_INFINITY;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_NINF;\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\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Tests if a finite double-precision floating-point number is an integer.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\treturn (floor(x) === x);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// TODO: implementation (?)\n\n/**\n* Rounds a double-precision floating-point number toward negative infinity.\n*\n* @param {number} x - input value\n* @returns {number} rounded value\n*\n* @example\n* var v = floor( -4.2 );\n* // returns -5.0\n*\n* @example\n* var v = floor( 9.99999 );\n* // returns 9.0\n*\n* @example\n* var v = floor( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = floor( NaN );\n* // returns NaN\n*/\nvar floor = Math.floor; // eslint-disable-line stdlib/no-builtin-math\n\n\n// EXPORTS //\n\nmodule.exports = floor;\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* Test if a finite double-precision floating-point number is an integer.\n*\n* @module @stdlib/math-base-assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/math-base-assert-is-integer' );\n*\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* bool = isInteger( 3.14 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isInteger = require( './is_integer.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar isInt = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests if a number primitive is an integer value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a number primitive is an integer value\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tvalue < PINF &&\n\t\tvalue > NINF &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having an integer value\n*\n* @example\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having an integer value\n*\n* @example\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an integer\n*\n* @example\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isInteger( -3.14 );\n* // returns false\n*\n* @example\n* var bool = isInteger( null );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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* Test if a value is an integer.\n*\n* @module @stdlib/assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/assert-is-integer' );\n*\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isInteger( -3.14 );\n* // returns false\n*\n* bool = isInteger( null );\n* // returns false\n*\n* @example\n* // Use interface to check for integer primitives...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n*\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*\n* @example\n* // Use interface to check for integer objects...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n*\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue.valueOf() >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a nonnegative integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a nonnegative integer\n*\n* @example\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( null );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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* Test if a value is a nonnegative integer.\n*\n* @module @stdlib/assert-is-nonnegative-integer\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' );\n*\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* bool = isNonNegativeInteger( null );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isObject;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNonNegativeInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isNonNegativeInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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// MAIN //\n\nvar getProto = Object.getPrototypeOf;\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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* Returns the value of the `__proto__` property.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {*} value of `__proto__` property\n*/\nfunction getProto( obj ) {\n\t// eslint-disable-next-line no-proto\n\treturn obj.__proto__;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar getProto = require( './proto.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {(Object|null)} prototype\n*/\nfunction getPrototypeOf( obj ) {\n\tvar proto = getProto( obj );\n\tif ( proto || proto === null ) {\n\t\treturn proto;\n\t}\n\tif ( nativeClass( obj.constructor ) === '[object Function]' ) {\n\t\t// May break if the constructor has been tampered with...\n\t\treturn obj.constructor.prototype;\n\t}\n\tif ( obj instanceof Object ) {\n\t\treturn Object.prototype;\n\t}\n\t// Return `null` for objects created via `Object.create( null )`. Also return `null` for cross-realm objects on browsers that lack `__proto__` support, such as IE < 11.\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar builtin = require( './native.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar getProto;\nif ( isFunction( Object.getPrototypeOf ) ) {\n\tgetProto = builtin;\n} else {\n\tgetProto = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar getProto = require( './detect.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @param {*} value - input value\n* @returns {(Object|null)} prototype\n*\n* @example\n* var proto = getPrototypeOf( {} );\n* // returns {}\n*/\nfunction getPrototypeOf( value ) {\n\tif (\n\t\tvalue === null ||\n\t\tvalue === void 0\n\t) {\n\t\treturn null;\n\t}\n\t// In order to ensure consistent ES5/ES6 behavior, cast input value to an object (strings, numbers, booleans); ES5 `Object.getPrototypeOf` throws when provided primitives and ES6 `Object.getPrototypeOf` casts:\n\tvalue = Object( value );\n\n\treturn getProto( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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* Return the prototype of a provided object.\n*\n* @module @stdlib/utils-get-prototype-of\n*\n* @example\n* var getPrototype = require( '@stdlib/utils-get-prototype-of' );\n*\n* var proto = getPrototype( {} );\n* // returns {}\n*/\n\n// MODULES //\n\nvar getPrototype = require( './get_prototype_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getPrototype;\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\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an `Error` object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `Error` object\n*\n* @example\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isError( {} );\n* // returns false\n*/\nfunction isError( value ) {\n\tif ( typeof value !== 'object' || value === null ) {\n\t\treturn false;\n\t}\n\t// Check for `Error` objects from the same realm (same Node.js `vm` or same `Window` object)...\n\tif ( value instanceof Error ) {\n\t\treturn true;\n\t}\n\t// Walk the prototype tree until we find an object having the desired native class...\n\twhile ( value ) {\n\t\tif ( nativeClass( value ) === '[object Error]' ) {\n\t\t\treturn true;\n\t\t}\n\t\tvalue = getPrototypeOf( value );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isError;\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* Test if a value is an `Error` object.\n*\n* @module @stdlib/assert-is-error\n*\n* @example\n* var isError = require( '@stdlib/assert-is-error' );\n*\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* bool = isError( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isError = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isError;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to parse a regular expression string.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*/\nfunction reRegExp() {\n\treturn /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/; // eslint-disable-line no-useless-escape\n}\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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* Return a regular expression to parse a regular expression string.\n*\n* @module @stdlib/regexp-regexp\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var parts = RE_REGEXP.exec( '/^.*$/ig' );\n* // returns [ '/^.*$/ig', '^.*$', 'ig', 'index': 0, 'input': '/^.*$/ig' ]\n*/\n\n// MAIN //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reRegExp = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reRegExp, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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\nvar reRegExp = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Matches parts of a regular expression string.\n*\n* Regular expression: `/^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/`\n*\n* - `/^\\/`\n* - match a string that begins with a `/`\n*\n* - `()`\n* - capture\n*\n* - `(?:)+`\n* - capture, but do not remember, a group of characters which occur one or more times\n*\n* - `\\\\\\/`\n* - match the literal `\\/`\n*\n* - `|`\n* - OR\n*\n* - `[^\\/]`\n* - anything which is not the literal `\\/`\n*\n* - `\\/`\n* - match the literal `/`\n*\n* - `([imgy]*)`\n* - capture any characters matching `imgy` occurring zero or more times\n*\n* - `$/`\n* - string end\n*\n*\n* @constant\n* @type {RegExp}\n* @default /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/\n*/\nvar RE_REGEXP = reRegExp();\n\n\n// EXPORTS //\n\nmodule.exports = RE_REGEXP;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar reRegExp = require( '@stdlib/regexp-regexp' );\n\n\n// MAIN //\n\n/**\n* Parses a regular expression string and returns a new regular expression.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} must provide a regular expression string\n* @returns {(RegExp|null)} regular expression or null\n*\n* @example\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\nfunction reFromString( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Capture the regular expression pattern and any flags:\n\tstr = reRegExp().exec( str );\n\n\t// Create a new regular expression:\n\treturn ( str ) ? new RegExp( str[1], str[2] ) : null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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* Create a regular expression from a regular expression string.\n*\n* @module @stdlib/utils-regexp-from-string\n*\n* @example\n* var reFromString = require( '@stdlib/utils-regexp-from-string' );\n*\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\n\n// MODULES //\n\nvar reFromString = require( './from_string.js' );\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is `NaN`.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 7.0 );\n* // returns false\n*/\nfunction isnan( x ) {\n\treturn ( x !== x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a `NaN` number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a `NaN` number primitive\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a double-precision floating-point numeric value is `NaN`.\n*\n* @module @stdlib/math-base-assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/math-base-assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 7.0 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isnan = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a value of `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a value of `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( null );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a value is `NaN`.\n*\n* @module @stdlib/assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( null );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isObject;\n*\n* var bool = isnan( NaN );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isnan = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isnan, 'isPrimitive', isPrimitive );\nsetReadOnly( isnan, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a collection.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is a collection\n*\n* @example\n* var bool = isCollection( [] );\n* // returns true\n*\n* @example\n* var bool = isCollection( {} );\n* // returns false\n*/\nfunction isCollection( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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\nvar isnan = require( '@stdlib/assert-is-nan' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Returns the first index at which a given element can be found.\n*\n* @param {ArrayLike} arr - array-like object\n* @param {*} searchElement - element to find\n* @param {integer} [fromIndex] - starting index (if negative, the start index is determined relative to last element)\n* @throws {TypeError} must provide an array-like object\n* @throws {TypeError} `fromIndex` must be an integer\n* @returns {integer} index or -1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 5 );\n* // returns -1\n*\n* @example\n* // Using a `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* @example\n* // `fromIndex` which exceeds `array` length:\n* var arr = [ 1, 2, 3, 4, 2, 5 ];\n* var idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* @example\n* // Negative `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* var idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* @example\n* // Negative `fromIndex` exceeding input `array` length:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* @example\n* // Array-like objects:\n* var str = 'bebop';\n* var idx = indexOf( str, 'o' );\n* // returns 3\n*/\nfunction indexOf( arr, searchElement, fromIndex ) {\n\tvar len;\n\tvar i;\n\tif ( !isCollection( arr ) && !isString( arr ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array-like object. Value: `' + arr + '`.' );\n\t}\n\tlen = arr.length;\n\tif ( len === 0 ) {\n\t\treturn -1;\n\t}\n\tif ( arguments.length === 3 ) {\n\t\tif ( !isInteger( fromIndex ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `fromIndex` must be an integer. Value: `' + fromIndex + '`.' );\n\t\t}\n\t\tif ( fromIndex >= 0 ) {\n\t\t\tif ( fromIndex >= len ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\ti = fromIndex;\n\t\t} else {\n\t\t\ti = len + fromIndex;\n\t\t\tif ( i < 0 ) {\n\t\t\t\ti = 0;\n\t\t\t}\n\t\t}\n\t} else {\n\t\ti = 0;\n\t}\n\t// Check for `NaN`...\n\tif ( isnan( searchElement ) ) {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( isnan( arr[i] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( arr[ i ] === searchElement ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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* Maximum length of a typed array.\n*\n* @module @stdlib/constants-array-max-typed-array-length\n*\n* @example\n* var MAX_TYPED_ARRAY_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n* // returns 9007199254740991\n*/\n\n// MAIN //\n\n/**\n* Maximum length of a typed array.\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n*/\nvar MAX_TYPED_ARRAY_LENGTH = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = MAX_TYPED_ARRAY_LENGTH;\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* Return the first index at which a given element can be found.\n*\n* @module @stdlib/utils-index-of\n*\n* @example\n* var indexOf = require( '@stdlib/utils-index-of' );\n*\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* arr = [ 4, 3, 2, 1 ];\n* idx = indexOf( arr, 5 );\n* // returns -1\n*\n* // Using a `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* // `fromIndex` which exceeds `array` length:\n* arr = [ 1, 2, 3, 4, 2, 5 ];\n* idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* // Negative `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* // Negative `fromIndex` exceeding input `array` length:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* // Array-like objects:\n* var str = 'bebop';\n* idx = indexOf( str, 'o' );\n* // returns 3\n*/\n\n// MODULES //\n\nvar indexOf = require( './index_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.keys()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\treturn Object.keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar keys = require( './builtin.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests the built-in `Object.keys()` implementation when provided `arguments`.\n*\n* @private\n* @returns {boolean} boolean indicating whether the built-in implementation returns the expected number of keys\n*/\nfunction test() {\n\treturn ( keys( arguments ) || '' ).length !== 2;\n}\n\n\n// MAIN //\n\n/**\n* Tests whether the built-in `Object.keys()` implementation supports providing `arguments` as an input value.\n*\n* ## Notes\n*\n* - Safari 5.0 does **not** support `arguments` as an input value.\n*\n* @private\n* @returns {boolean} boolean indicating whether a built-in implementation supports `arguments`\n*/\nfunction check() {\n\treturn test( 1, 2 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\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// MAIN //\n\nvar bool = ( typeof Object.keys !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn ( nativeClass( value ) === '[object Arguments]' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( './main.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment returns the expected internal class of the `arguments` object.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment behaves as expected\n*\n* @example\n* var bool = detect();\n* // returns \n*/\nfunction detect() {\n\treturn isArguments( arguments );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnum = require( './native.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment has a bug where String indices are not detected as \"enumerable\" properties. Observed in Node v0.10.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment has the bug\n*/\nfunction detect() {\n\treturn !isEnum.call( 'beep', '0' );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @private\n* @name isEnumerableProperty\n* @type {Function}\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nvar isEnumerableProperty = Object.prototype.propertyIsEnumerable;\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar isString = require( '@stdlib/assert-is-string' );\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isEnum = require( './native.js' );\nvar hasStringEnumBug = require( './has_string_enumerability_bug.js' );\n\n\n// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nfunction isEnumerableProperty( value, property ) {\n\tvar bool;\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\tbool = isEnum.call( value, property );\n\tif ( !bool && hasStringEnumBug && isString( value ) ) {\n\t\t// Note: we only check for indices, as properties attached to a `String` object are properly detected as enumerable above.\n\t\tproperty = +property;\n\t\treturn (\n\t\t\t!isnan( property ) &&\n\t\t\tisInteger( property ) &&\n\t\t\tproperty >= 0 &&\n\t\t\tproperty < value.length\n\t\t);\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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* Test whether an object's own property is enumerable.\n*\n* @module @stdlib/assert-is-enumerable-property\n*\n* @example\n* var isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\n\n// MODULES //\n\nvar isEnumerableProperty = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-uint32-max' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object' &&\n\t\t!isArray( value ) &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH &&\n\t\thasOwnProp( value, 'callee' ) &&\n\t\t!isEnumerableProperty( value, 'callee' )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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* Test if a value is an `arguments` object.\n*\n* @module @stdlib/assert-is-arguments\n*\n* @example\n* var isArguments = require( '@stdlib/assert-is-arguments' );\n*\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* bool = isArguments( [] );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasArgumentsClass = require( './detect.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar isArguments;\nif ( hasArgumentsClass ) {\n\tisArguments = main;\n} else {\n\tisArguments = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar builtin = require( './builtin.js' );\n\n\n// VARIABLES //\n\nvar slice = Array.prototype.slice;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tif ( isArguments( value ) ) {\n\t\treturn builtin( slice.call( value ) );\n\t}\n\treturn builtin( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* No operation.\n*\n* @example\n* noop();\n* // ...does nothing.\n*/\nfunction noop() {\n\t// Empty function...\n}\n\n\n// EXPORTS //\n\nmodule.exports = noop;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar noop = require( '@stdlib/utils-noop' );\n\n\n// MAIN //\n\n// Note: certain environments treat an object's prototype as enumerable, which, as a matter of convention, it shouldn't be...\nvar bool = isEnumerableProperty( noop, 'prototype' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n\n\n// VARIABLES //\n\nvar obj = {\n\t'toString': null\n};\n\n\n// MAIN //\n\n// Note: certain environments don't allow enumeration of overwritten properties which are considered non-enumerable...\nvar bool = !isEnumerableProperty( obj, 'toString' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests whether a value equals the prototype of its constructor.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction isConstructorPrototype( value ) {\n\treturn ( value.constructor && value.constructor.prototype === value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isConstructorPrototype;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar EXCLUDED_KEYS = require( './excluded_keys.json' );\nvar win = require( './window.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Determines whether an environment throws when comparing to the prototype of a value's constructor (e.g., [IE9][1]).\n*\n* [1]: https://stackoverflow.com/questions/7688070/why-is-comparing-the-constructor-property-of-two-windows-unreliable\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment is buggy\n*/\nfunction check() {\n\tvar k;\n\tif ( typeOf( win ) === 'undefined' ) {\n\t\treturn false;\n\t}\n\tfor ( k in win ) { // eslint-disable-line guard-for-in\n\t\ttry {\n\t\t\tif (\n\t\t\t\tindexOf( EXCLUDED_KEYS, k ) === -1 &&\n\t\t\t\thasOwnProp( win, k ) &&\n\t\t\t\twin[ k ] !== null &&\n\t\t\t\ttypeOf( win[ k ] ) === 'object'\n\t\t\t) {\n\t\t\t\tisConstructorPrototype( win[ k ] );\n\t\t\t}\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// MAIN //\n\nbool = check();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\nvar w = ( typeof window === 'undefined' ) ? void 0 : window;\n\n\n// EXPORTS //\n\nmodule.exports = w;\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// MAIN //\n\nvar bool = ( typeof window !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar hasAutomationEqualityBug = require( './has_automation_equality_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar HAS_WINDOW = require( './has_window.js' );\n\n\n// MAIN //\n\n/**\n* Wraps the test for constructor prototype equality to accommodate buggy environments (e.g., environments which throw when testing equality).\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction wrapper( value ) {\n\tif ( HAS_WINDOW === false && !hasAutomationEqualityBug ) {\n\t\treturn isConstructorPrototype( value );\n\t}\n\ttry {\n\t\treturn isConstructorPrototype( value );\n\t} catch ( error ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = wrapper;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar HAS_ENUM_PROTO_BUG = require( './has_enumerable_prototype_bug.js' );\nvar HAS_NON_ENUM_PROPS_BUG = require( './has_non_enumerable_properties_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype_wrapper.js' );\nvar NON_ENUMERABLE = require( './non_enumerable.json' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tvar skipConstructor;\n\tvar skipPrototype;\n\tvar isFcn;\n\tvar out;\n\tvar k;\n\tvar p;\n\tvar i;\n\n\tout = [];\n\tif ( isArguments( value ) ) {\n\t\t// Account for environments which treat `arguments` differently...\n\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\tout.push( i.toString() );\n\t\t}\n\t\t// Note: yes, we are precluding the `arguments` array-like object from having other enumerable properties; however, this should (1) be very rare and (2) not be encouraged (e.g., doing something like `arguments.a = 'b'`; in certain engines directly manipulating the `arguments` value results in automatic de-optimization).\n\t\treturn out;\n\t}\n\tif ( typeof value === 'string' ) {\n\t\t// Account for environments which do not treat string character indices as \"own\" properties...\n\t\tif ( value.length > 0 && !hasOwnProp( value, '0' ) ) {\n\t\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\t\tout.push( i.toString() );\n\t\t\t}\n\t\t}\n\t} else {\n\t\tisFcn = ( typeof value === 'function' );\n\t\tif ( isFcn === false && !isObjectLike( value ) ) {\n\t\t\treturn out;\n\t\t}\n\t\tskipPrototype = ( HAS_ENUM_PROTO_BUG && isFcn );\n\t}\n\tfor ( k in value ) {\n\t\tif ( !( skipPrototype && k === 'prototype' ) && hasOwnProp( value, k ) ) {\n\t\t\tout.push( String( k ) );\n\t\t}\n\t}\n\tif ( HAS_NON_ENUM_PROPS_BUG ) {\n\t\tskipConstructor = isConstructorPrototype( value );\n\t\tfor ( i = 0; i < NON_ENUMERABLE.length; i++ ) {\n\t\t\tp = NON_ENUMERABLE[ i ];\n\t\t\tif ( !( skipConstructor && p === 'constructor' ) && hasOwnProp( value, p ) ) {\n\t\t\t\tout.push( String( p ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar hasArgumentsBug = require( './has_arguments_bug.js' );\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar wrapper = require( './builtin_wrapper.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @name keys\n* @type {Function}\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nvar keys;\nif ( HAS_BUILTIN ) {\n\tif ( hasArgumentsBug() ) {\n\t\tkeys = wrapper;\n\t} else {\n\t\tkeys = builtin;\n\t}\n} else {\n\tkeys = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* Return an array of an object's own enumerable property names.\n*\n* @module @stdlib/utils-keys\n*\n* @example\n* var keys = require( '@stdlib/utils-keys' );\n*\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\n\n// MODULES //\n\nvar keys = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyNames !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyNames = Object.getOwnPropertyNames;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn propertyNames( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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\nvar keys = require( '@stdlib/utils-keys' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n* - In environments lacking support for `Object.getOwnPropertyNames()`, property descriptors are unavailable, and thus all properties can be safely assumed to be enumerable. Hence, we can defer to calling `Object.keys`, which retrieves all own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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* Return an array of an object's own enumerable and non-enumerable property names.\n*\n* @module @stdlib/utils-property-names\n*\n* @example\n* var getOwnPropertyNames = require( '@stdlib/utils-property-names' );\n*\n* var keys = getOwnPropertyNames({\n* 'foo': 'bar',\n* 'beep': 'boop'\n* });\n* // e.g., returns [ 'foo', 'beep' ]\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyDescriptor !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyDescriptor = Object.getOwnPropertyDescriptor;\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tvar desc;\n\tif ( value === null || value === void 0 ) {\n\t\treturn null;\n\t}\n\tdesc = propertyDescriptor( value, property );\n\treturn ( desc === void 0 ) ? null : desc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n* - In environments lacking `Object.getOwnPropertyDescriptor()` support, property descriptors do not exist. In non-supporting environment, if an object has a provided property, this function returns a descriptor object equivalent to that returned in a supporting environment; otherwise, the function returns `null`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tif ( hasOwnProp( value, property ) ) {\n\t\treturn {\n\t\t\t'configurable': true,\n\t\t\t'enumerable': true,\n\t\t\t'writable': true,\n\t\t\t'value': value[ property ]\n\t\t};\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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* Return a property descriptor for an object's own property.\n*\n* @module @stdlib/utils-property-descriptor\n*\n* @example\n* var getOwnPropertyDescriptor = require( '@stdlib/utils-property-descriptor' );\n*\n* var obj = {\n* 'foo': 'bar',\n* 'beep': 'boop'\n* };\n*\n* var keys = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':'bar'}\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// TODO: write (browser) polyfill\n\n// MAIN //\n\n/**\n* Buffer constructor.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Buffer constructor.\n*\n* @module @stdlib/buffer-ctor\n*\n* @example\n* var ctor = require( '@stdlib/buffer-ctor' );\n*\n* var b = new ctor( [ 1, 2, 3, 4 ] );\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\nvar main = require( './buffer.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasNodeBufferSupport() ) {\n\tctor = main;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = require( 'buffer' ).Buffer; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\nvar bool = isFunction( Buffer.from );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn Buffer.from( buffer );\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn new Buffer( buffer ); // eslint-disable-line no-buffer-constructor\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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* Copy buffer data to a new `Buffer` instance.\n*\n* @module @stdlib/buffer-from-buffer\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n* var copyBuffer = require( '@stdlib/buffer-from-buffer' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = copyBuffer( b1 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFrom = require( './has_from.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar copyBuffer;\nif ( hasFrom ) {\n\tcopyBuffer = main;\n} else {\n\tcopyBuffer = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt8Array = ( typeof Int8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int8Array\n*\n* @example\n* var bool = isInt8Array( new Int8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt8Array( [] );\n* // returns false\n*/\nfunction isInt8Array( value ) {\n\treturn (\n\t\t( hasInt8Array && value instanceof Int8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt8Array;\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// MAIN //\n\nvar main = ( typeof Int8Array === 'function' ) ? Int8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt8Array = require( '@stdlib/assert-is-int8array' );\nvar INT8_MAX = require( '@stdlib/constants-int8-max' );\nvar INT8_MIN = require( '@stdlib/constants-int8-min' );\nvar GlobalInt8Array = require( './int8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int8Array` support\n*\n* @example\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\nfunction hasInt8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt8Array( [ 1, 3.14, -3.14, INT8_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT8_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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* Minimum signed 8-bit integer.\n*\n* @module @stdlib/constants-int8-min\n* @type {integer32}\n*\n* @example\n* var INT8_MIN = require( '@stdlib/constants-int8-min' );\n* // returns -128\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 8-bit integer.\n*\n* ## Notes\n*\n* The number is given by\n*\n* ```tex\n* -(2^{7})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -128\n*/\nvar INT8_MIN = -128|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT8_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int8\n*\n* @example\n* var ctor = require( '@stdlib/array-int8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\nvar builtin = require( './int8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int8Array === 'function' ) ? Int8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int8Array` support.\n*\n* @module @stdlib/assert-has-int8array-support\n*\n* @example\n* var hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\n*\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8Array = ( typeof Uint8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8Array\n*\n* @example\n* var bool = isUint8Array( new Uint8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8Array( [] );\n* // returns false\n*/\nfunction isUint8Array( value ) {\n\treturn (\n\t\t( hasUint8Array && value instanceof Uint8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8Array;\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// MAIN //\n\nvar main = ( typeof Uint8Array === 'function' ) ? Uint8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8Array = require( '@stdlib/assert-is-uint8array' );\nvar UINT8_MAX = require( '@stdlib/constants-uint8-max' );\nvar GlobalUint8Array = require( './uint8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8Array` support\n*\n* @example\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\nfunction hasUint8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT8_MAX+1, UINT8_MAX+2 ];\n\t\tarr = new GlobalUint8Array( arr );\n\t\tbool = (\n\t\t\tisUint8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT8_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint8\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\nvar builtin = require( './uint8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8Array === 'function' ) ? Uint8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8Array` support.\n*\n* @module @stdlib/assert-has-uint8array-support\n*\n* @example\n* var hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\n*\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8ClampedArray = ( typeof Uint8ClampedArray === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8ClampedArray.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8ClampedArray\n*\n* @example\n* var bool = isUint8ClampedArray( new Uint8ClampedArray( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8ClampedArray( [] );\n* // returns false\n*/\nfunction isUint8ClampedArray( value ) {\n\treturn (\n\t\t( hasUint8ClampedArray && value instanceof Uint8ClampedArray ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8ClampedArray]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8ClampedArray;\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// MAIN //\n\nvar main = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8ClampedArray = require( '@stdlib/assert-is-uint8clampedarray' );\nvar GlobalUint8ClampedArray = require( './uint8clampedarray.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8ClampedArray` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8ClampedArray` support\n*\n* @example\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\nfunction hasUint8ClampedArraySupport() { // eslint-disable-line id-length\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8ClampedArray !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalUint8ClampedArray( [ -1, 0, 1, 3.14, 4.99, 255, 256 ] );\n\t\tbool = (\n\t\t\tisUint8ClampedArray( arr ) &&\n\t\t\tarr[ 0 ] === 0 && // clamped\n\t\t\tarr[ 1 ] === 0 &&\n\t\t\tarr[ 2 ] === 1 &&\n\t\t\tarr[ 3 ] === 3 && // round to nearest\n\t\t\tarr[ 4 ] === 5 && // round to nearest\n\t\t\tarr[ 5 ] === 255 &&\n\t\t\tarr[ 6 ] === 255 // clamped\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @module @stdlib/array-uint8c\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8c' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' ); // eslint-disable-line id-length\nvar builtin = require( './uint8clampedarray.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ClampedArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8ClampedArray` support.\n*\n* @module @stdlib/assert-has-uint8clampedarray-support\n*\n* @example\n* var hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' );\n*\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt16Array = ( typeof Int16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int16Array\n*\n* @example\n* var bool = isInt16Array( new Int16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt16Array( [] );\n* // returns false\n*/\nfunction isInt16Array( value ) {\n\treturn (\n\t\t( hasInt16Array && value instanceof Int16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt16Array;\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// MAIN //\n\nvar main = ( typeof Int16Array === 'function' ) ? Int16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt16Array = require( '@stdlib/assert-is-int16array' );\nvar INT16_MAX = require( '@stdlib/constants-int16-max' );\nvar INT16_MIN = require( '@stdlib/constants-int16-min' );\nvar GlobalInt16Array = require( './int16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int16Array` support\n*\n* @example\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\nfunction hasInt16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt16Array( [ 1, 3.14, -3.14, INT16_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT16_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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* Minimum signed 16-bit integer.\n*\n* @module @stdlib/constants-int16-min\n* @type {integer32}\n*\n* @example\n* var INT16_MIN = require( '@stdlib/constants-int16-min' );\n* // returns -32768\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 16-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{15})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 1000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -32768\n*/\nvar INT16_MIN = -32768|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT16_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int16\n*\n* @example\n* var ctor = require( '@stdlib/array-int16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\nvar builtin = require( './int16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int16Array === 'function' ) ? Int16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int16Array` support.\n*\n* @module @stdlib/assert-has-int16array-support\n*\n* @example\n* var hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\n*\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint16Array = ( typeof Uint16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint16Array\n*\n* @example\n* var bool = isUint16Array( new Uint16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint16Array( [] );\n* // returns false\n*/\nfunction isUint16Array( value ) {\n\treturn (\n\t\t( hasUint16Array && value instanceof Uint16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint16Array;\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// MAIN //\n\nvar main = ( typeof Uint16Array === 'function' ) ? Uint16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint16Array = require( '@stdlib/assert-is-uint16array' );\nvar UINT16_MAX = require( '@stdlib/constants-uint16-max' );\nvar GlobalUint16Array = require( './uint16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint16Array` support\n*\n* @example\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\nfunction hasUint16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT16_MAX+1, UINT16_MAX+2 ];\n\t\tarr = new GlobalUint16Array( arr );\n\t\tbool = (\n\t\t\tisUint16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT16_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 16-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint16\n*\n* @example\n* var ctor = require( '@stdlib/array-uint16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\nvar builtin = require( './uint16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint16Array === 'function' ) ? Uint16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint16Array` support.\n*\n* @module @stdlib/assert-has-uint16array-support\n*\n* @example\n* var hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\n*\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt32Array = ( typeof Int32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int32Array\n*\n* @example\n* var bool = isInt32Array( new Int32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt32Array( [] );\n* // returns false\n*/\nfunction isInt32Array( value ) {\n\treturn (\n\t\t( hasInt32Array && value instanceof Int32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt32Array;\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// MAIN //\n\nvar main = ( typeof Int32Array === 'function' ) ? Int32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt32Array = require( '@stdlib/assert-is-int32array' );\nvar INT32_MAX = require( '@stdlib/constants-int32-max' );\nvar INT32_MIN = require( '@stdlib/constants-int32-min' );\nvar GlobalInt32Array = require( './int32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int32Array` support\n*\n* @example\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\nfunction hasInt32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt32Array( [ 1, 3.14, -3.14, INT32_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT32_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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* Minimum signed 32-bit integer.\n*\n* @module @stdlib/constants-int32-min\n* @type {integer32}\n*\n* @example\n* var INT32_MIN = require( '@stdlib/constants-int32-min' );\n* // returns -2147483648\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 32-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{31})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -2147483648\n*/\nvar INT32_MIN = -2147483648|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT32_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int32\n*\n* @example\n* var ctor = require( '@stdlib/array-int32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\nvar builtin = require( './int32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int32Array === 'function' ) ? Int32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int32Array` support.\n*\n* @module @stdlib/assert-has-int32array-support\n*\n* @example\n* var hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\n*\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint32Array = ( typeof Uint32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint32Array\n*\n* @example\n* var bool = isUint32Array( new Uint32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint32Array( [] );\n* // returns false\n*/\nfunction isUint32Array( value ) {\n\treturn (\n\t\t( hasUint32Array && value instanceof Uint32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint32Array;\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// MAIN //\n\nvar main = ( typeof Uint32Array === 'function' ) ? Uint32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint32Array = require( '@stdlib/assert-is-uint32array' );\nvar UINT32_MAX = require( '@stdlib/constants-uint32-max' );\nvar GlobalUint32Array = require( './uint32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint32Array` support\n*\n* @example\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\nfunction hasUint32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT32_MAX+1, UINT32_MAX+2 ];\n\t\tarr = new GlobalUint32Array( arr );\n\t\tbool = (\n\t\t\tisUint32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT32_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 32-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint32\n*\n* @example\n* var ctor = require( '@stdlib/array-uint32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\nvar builtin = require( './uint32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint32Array === 'function' ) ? Uint32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint32Array` support.\n*\n* @module @stdlib/assert-has-uint32array-support\n*\n* @example\n* var hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\n*\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat32Array = ( typeof Float32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float32Array\n*\n* @example\n* var bool = isFloat32Array( new Float32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat32Array( [] );\n* // returns false\n*/\nfunction isFloat32Array( value ) {\n\treturn (\n\t\t( hasFloat32Array && value instanceof Float32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat32Array;\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// MAIN //\n\nvar main = ( typeof Float32Array === 'function' ) ? Float32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat32Array = require( '@stdlib/assert-is-float32array' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar GlobalFloat32Array = require( './float32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float32Array` support\n*\n* @example\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\nfunction hasFloat32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat32Array( [ 1.0, 3.14, -3.14, 5.0e40 ] );\n\t\tbool = (\n\t\t\tisFloat32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.140000104904175 &&\n\t\t\tarr[ 2 ] === -3.140000104904175 &&\n\t\t\tarr[ 3 ] === PINF\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of single-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float32\n*\n* @example\n* var ctor = require( '@stdlib/array-float32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\nvar builtin = require( './float32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float32Array === 'function' ) ? Float32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float32Array` support.\n*\n* @module @stdlib/assert-has-float32array-support\n*\n* @example\n* var hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\n*\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat64Array = ( typeof Float64Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float64Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float64Array\n*\n* @example\n* var bool = isFloat64Array( new Float64Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat64Array( [] );\n* // returns false\n*/\nfunction isFloat64Array( value ) {\n\treturn (\n\t\t( hasFloat64Array && value instanceof Float64Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float64Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat64Array;\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// MAIN //\n\nvar main = ( typeof Float64Array === 'function' ) ? Float64Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat64Array = require( '@stdlib/assert-is-float64array' );\nvar GlobalFloat64Array = require( './float64array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float64Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float64Array` support\n*\n* @example\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\nfunction hasFloat64ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat64Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat64Array( [ 1.0, 3.14, -3.14, NaN ] );\n\t\tbool = (\n\t\t\tisFloat64Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.14 &&\n\t\t\tarr[ 2 ] === -3.14 &&\n\t\t\tarr[ 3 ] !== arr[ 3 ]\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of double-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float64\n*\n* @example\n* var ctor = require( '@stdlib/array-float64' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\nvar builtin = require( './float64array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat64ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float64Array === 'function' ) ? Float64Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float64Array` support.\n*\n* @module @stdlib/assert-has-float64array-support\n*\n* @example\n* var hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\n*\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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\nvar Int8Array = require( '@stdlib/array-int8' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar Uint8ClampedArray = require( '@stdlib/array-uint8c' );\nvar Int16Array = require( '@stdlib/array-int16' );\nvar Uint16Array = require( '@stdlib/array-uint16' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar Uint32Array = require( '@stdlib/array-uint32' );\nvar Float32Array = require( '@stdlib/array-float32' );\nvar Float64Array = require( '@stdlib/array-float64' );\n\n\n// VARIABLES //\n\nvar hash;\n\n\n// FUNCTIONS //\n\n/**\n* Copies an `Int8Array`.\n*\n* @private\n* @param {Int8Array} arr - array to copy\n* @returns {Int8Array} new array\n*/\nfunction int8array( arr ) {\n\treturn new Int8Array( arr );\n}\n\n/**\n* Copies a `Uint8Array`.\n*\n* @private\n* @param {Uint8Array} arr - array to copy\n* @returns {Uint8Array} new array\n*/\nfunction uint8array( arr ) {\n\treturn new Uint8Array( arr );\n}\n\n/**\n* Copies a `Uint8ClampedArray`.\n*\n* @private\n* @param {Uint8ClampedArray} arr - array to copy\n* @returns {Uint8ClampedArray} new array\n*/\nfunction uint8clampedarray( arr ) {\n\treturn new Uint8ClampedArray( arr );\n}\n\n/**\n* Copies an `Int16Array`.\n*\n* @private\n* @param {Int16Array} arr - array to copy\n* @returns {Int16Array} new array\n*/\nfunction int16array( arr ) {\n\treturn new Int16Array( arr );\n}\n\n/**\n* Copies a `Uint16Array`.\n*\n* @private\n* @param {Uint16Array} arr - array to copy\n* @returns {Uint16Array} new array\n*/\nfunction uint16array( arr ) {\n\treturn new Uint16Array( arr );\n}\n\n/**\n* Copies an `Int32Array`.\n*\n* @private\n* @param {Int32Array} arr - array to copy\n* @returns {Int32Array} new array\n*/\nfunction int32array( arr ) {\n\treturn new Int32Array( arr );\n}\n\n/**\n* Copies a `Uint32Array`.\n*\n* @private\n* @param {Uint32Array} arr - array to copy\n* @returns {Uint32Array} new array\n*/\nfunction uint32array( arr ) {\n\treturn new Uint32Array( arr );\n}\n\n/**\n* Copies a `Float32Array`.\n*\n* @private\n* @param {Float32Array} arr - array to copy\n* @returns {Float32Array} new array\n*/\nfunction float32array( arr ) {\n\treturn new Float32Array( arr );\n}\n\n/**\n* Copies a `Float64Array`.\n*\n* @private\n* @param {Float64Array} arr - array to copy\n* @returns {Float64Array} new array\n*/\nfunction float64array( arr ) {\n\treturn new Float64Array( arr );\n}\n\n/**\n* Returns a hash of functions for copying typed arrays.\n*\n* @private\n* @returns {Object} function hash\n*/\nfunction typedarrays() {\n\tvar out = {\n\t\t'int8array': int8array,\n\t\t'uint8array': uint8array,\n\t\t'uint8clampedarray': uint8clampedarray,\n\t\t'int16array': int16array,\n\t\t'uint16array': uint16array,\n\t\t'int32array': int32array,\n\t\t'uint32array': uint32array,\n\t\t'float32array': float32array,\n\t\t'float64array': float64array\n\t};\n\treturn out;\n}\n\n\n// MAIN //\n\nhash = typedarrays();\n\n\n// EXPORTS //\n\nmodule.exports = hash;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar regexp = require( '@stdlib/utils-regexp-from-string' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar propertyNames = require( '@stdlib/utils-property-names' );\nvar propertyDescriptor = require( '@stdlib/utils-property-descriptor' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar defineProperty = require( '@stdlib/utils-define-property' );\nvar copyBuffer = require( '@stdlib/buffer-from-buffer' );\nvar typedArrays = require( './typed_arrays.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Clones a class instance.\n*\n* ## Notes\n*\n* - This should **only** be used for simple cases. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This approach should be considered **fragile**.\n* - The function is greedy, disregarding the notion of a `level`. Instead, the function deep copies all properties, as we assume the concept of `level` applies only to the class instance reference but not to its internal state. This prevents, in theory, two instances from sharing state.\n*\n*\n* @private\n* @param {Object} val - class instance\n* @returns {Object} new instance\n*/\nfunction cloneInstance( val ) {\n\tvar cache;\n\tvar names;\n\tvar name;\n\tvar refs;\n\tvar desc;\n\tvar tmp;\n\tvar ref;\n\tvar i;\n\n\tcache = [];\n\trefs = [];\n\n\tref = Object.create( getPrototypeOf( val ) );\n\tcache.push( val );\n\trefs.push( ref );\n\n\tnames = propertyNames( val );\n\tfor ( i = 0; i < names.length; i++ ) {\n\t\tname = names[ i ];\n\t\tdesc = propertyDescriptor( val, name );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( val[name] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( val[name], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( ref, name, desc );\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( ref );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( ref );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( ref );\n\t}\n\treturn ref;\n}\n\n/**\n* Copies an error object.\n*\n* @private\n* @param {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error - error to copy\n* @returns {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error copy\n*\n* @example\n* var err1 = new TypeError( 'beep' );\n*\n* var err2 = copyError( err1 );\n* // returns \n*/\nfunction copyError( error ) {\n\tvar cache = [];\n\tvar refs = [];\n\tvar keys;\n\tvar desc;\n\tvar tmp;\n\tvar key;\n\tvar err;\n\tvar i;\n\n\t// Create a new error...\n\terr = new error.constructor( error.message );\n\n\tcache.push( error );\n\trefs.push( err );\n\n\t// If a `stack` property is present, copy it over...\n\tif ( error.stack ) {\n\t\terr.stack = error.stack;\n\t}\n\t// Node.js specific (system errors)...\n\tif ( error.code ) {\n\t\terr.code = error.code;\n\t}\n\tif ( error.errno ) {\n\t\terr.errno = error.errno;\n\t}\n\tif ( error.syscall ) {\n\t\terr.syscall = error.syscall;\n\t}\n\t// Any enumerable properties...\n\tkeys = objectKeys( error );\n\tfor ( i = 0; i < keys.length; i++ ) {\n\t\tkey = keys[ i ];\n\t\tdesc = propertyDescriptor( error, key );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( error[ key ] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( error[ key ], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( err, key, desc );\n\t}\n\treturn err;\n}\n\n\n// MAIN //\n\n/**\n* Recursively performs a deep copy of an input object.\n*\n* @private\n* @param {*} val - value to copy\n* @param {(Array|Object)} copy - copy\n* @param {Array} cache - an array of visited objects\n* @param {Array} refs - an array of object references\n* @param {NonNegativeInteger} level - copy depth\n* @returns {*} deep copy\n*/\nfunction deepCopy( val, copy, cache, refs, level ) {\n\tvar parent;\n\tvar keys;\n\tvar name;\n\tvar desc;\n\tvar ctor;\n\tvar key;\n\tvar ref;\n\tvar x;\n\tvar i;\n\tvar j;\n\n\tlevel -= 1;\n\n\t// Primitives and functions...\n\tif (\n\t\ttypeof val !== 'object' ||\n\t\tval === null\n\t) {\n\t\treturn val;\n\t}\n\tif ( isBuffer( val ) ) {\n\t\treturn copyBuffer( val );\n\t}\n\tif ( isError( val ) ) {\n\t\treturn copyError( val );\n\t}\n\t// Objects...\n\tname = typeOf( val );\n\n\tif ( name === 'date' ) {\n\t\treturn new Date( +val );\n\t}\n\tif ( name === 'regexp' ) {\n\t\treturn regexp( val.toString() );\n\t}\n\tif ( name === 'set' ) {\n\t\treturn new Set( val );\n\t}\n\tif ( name === 'map' ) {\n\t\treturn new Map( val );\n\t}\n\tif (\n\t\tname === 'string' ||\n\t\tname === 'boolean' ||\n\t\tname === 'number'\n\t) {\n\t\t// If provided an `Object`, return an equivalent primitive!\n\t\treturn val.valueOf();\n\t}\n\tctor = typedArrays[ name ];\n\tif ( ctor ) {\n\t\treturn ctor( val );\n\t}\n\t// Class instances...\n\tif (\n\t\tname !== 'array' &&\n\t\tname !== 'object'\n\t) {\n\t\t// Cloning requires ES5 or higher...\n\t\tif ( typeof Object.freeze === 'function' ) {\n\t\t\treturn cloneInstance( val );\n\t\t}\n\t\treturn {};\n\t}\n\t// Arrays and plain objects...\n\tkeys = objectKeys( val );\n\tif ( level > 0 ) {\n\t\tparent = name;\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tx = val[ key ];\n\n\t\t\t// Primitive, Buffer, special class instance...\n\t\t\tname = typeOf( x );\n\t\t\tif (\n\t\t\t\ttypeof x !== 'object' ||\n\t\t\t\tx === null ||\n\t\t\t\t(\n\t\t\t\t\tname !== 'array' &&\n\t\t\t\t\tname !== 'object'\n\t\t\t\t) ||\n\t\t\t\tisBuffer( x )\n\t\t\t) {\n\t\t\t\tif ( parent === 'object' ) {\n\t\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\t\tdesc.value = deepCopy( x );\n\t\t\t\t\t}\n\t\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t\t} else {\n\t\t\t\t\tcopy[ key ] = deepCopy( x );\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Circular reference...\n\t\t\ti = indexOf( cache, x );\n\t\t\tif ( i !== -1 ) {\n\t\t\t\tcopy[ key ] = refs[ i ];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Plain array or object...\n\t\t\tref = ( isArray( x ) ) ? new Array( x.length ) : {};\n\t\t\tcache.push( x );\n\t\t\trefs.push( ref );\n\t\t\tif ( parent === 'array' ) {\n\t\t\t\tcopy[ key ] = deepCopy( x, ref, cache, refs, level );\n\t\t\t} else {\n\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\tdesc.value = deepCopy( x, ref, cache, refs, level );\n\t\t\t\t}\n\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t}\n\t\t}\n\t} else if ( name === 'array' ) {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tcopy[ key ] = val[ key ];\n\t\t}\n\t} else {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\tdefineProperty( copy, key, desc );\n\t\t}\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( copy );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( copy );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( copy );\n\t}\n\treturn copy;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepCopy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar deepCopy = require( './deep_copy.js' );\n\n\n// MAIN //\n\n/**\n* Copies or deep clones a value to an arbitrary depth.\n*\n* @param {*} value - value to copy\n* @param {NonNegativeInteger} [level=+infinity] - copy depth\n* @throws {TypeError} `level` must be a nonnegative integer\n* @returns {*} value copy\n*\n* @example\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\nfunction copy( value, level ) {\n\tvar out;\n\tif ( arguments.length > 1 ) {\n\t\tif ( !isNonNegativeInteger( level ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `level` must be a nonnegative integer. Value: `' + level + '`.' );\n\t\t}\n\t\tif ( level === 0 ) {\n\t\t\treturn value;\n\t\t}\n\t} else {\n\t\tlevel = PINF;\n\t}\n\tout = ( isArray( value ) ) ? new Array( value.length ) : {};\n\treturn deepCopy( value, out, [value], [out], level );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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* Copy or deep clone a value to an arbitrary depth.\n*\n* @module @stdlib/utils-copy\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ {'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\n\n// MODULES //\n\nvar copy = require( './copy.js' );\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an object; e.g., `{}`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an object\n*\n* @example\n* var bool = isObject( {} );\n* // returns true\n*\n* @example\n* var bool = isObject( null );\n* // returns false\n*/\nfunction isObject( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t!isArray( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObject;\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\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar objectPrototype = Object.prototype;\n\n\n// FUNCTIONS //\n\n/**\n* Tests that an object only has own properties.\n*\n* @private\n* @param {Object} obj - value to test\n* @returns {boolean} boolean indicating if an object only has own properties\n*/\nfunction ownProps( obj ) {\n\tvar key;\n\n\t// NOTE: possibility of perf boost if key enumeration order is known (see http://stackoverflow.com/questions/18531624/isplainobject-thing).\n\tfor ( key in obj ) {\n\t\tif ( !hasOwnProp( obj, key ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n\n// MAIN //\n\n/**\n* Tests if a value is a plain object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a plain object\n*\n* @example\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* @example\n* var bool = isPlainObject( null );\n* // returns false\n*/\nfunction isPlainObject( value ) {\n\tvar proto;\n\n\t// Screen for obvious non-objects...\n\tif ( !isObject( value ) ) {\n\t\treturn false;\n\t}\n\t// Objects with no prototype (e.g., `Object.create( null )`) are plain...\n\tproto = getPrototypeOf( value );\n\tif ( !proto ) {\n\t\treturn true;\n\t}\n\t// Objects having a prototype are plain if and only if they are constructed with a global `Object` function and the prototype points to the prototype of a plain object...\n\treturn (\n\t\t// Cannot have own `constructor` property:\n\t\t!hasOwnProp( value, 'constructor' ) &&\n\n\t\t// Prototype `constructor` property must be a function (see also https://bugs.jquery.com/ticket/9897 and http://stackoverflow.com/questions/18531624/isplainobject-thing):\n\t\thasOwnProp( proto, 'constructor' ) &&\n\t\tisFunction( proto.constructor ) &&\n\t\tnativeClass( proto.constructor ) === '[object Function]' &&\n\n\t\t// Test for object-specific method:\n\t\thasOwnProp( proto, 'isPrototypeOf' ) &&\n\t\tisFunction( proto.isPrototypeOf ) &&\n\n\t\t(\n\t\t\t// Test if the prototype matches the global `Object` prototype (same realm):\n\t\t\tproto === objectPrototype ||\n\n\t\t\t// Test that all properties are own properties (cross-realm; *most* likely a plain object):\n\t\t\townProps( value )\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - options to validate\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {(Error|null)} error object or null\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );\n\t}\n\tif ( hasOwnProp( options, 'url' ) ) {\n\t\topts.url = options.url;\n\t\tif ( !isString( opts.url ) ) {\n\t\t\treturn new TypeError( 'invalid option. `url` option must be a string primitive. Option: `' + opts.url + '`.' );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'message' ) ) {\n\t\topts.message = options.message;\n\t\tif ( !isString( opts.message ) ) {\n\t\t\treturn new TypeError( 'invalid option. `message` option must be a string primitive. Option: `' + opts.message + '`.' );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\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* Test if a value is a plain object.\n*\n* @module @stdlib/assert-is-plain-object\n*\n* @example\n* var isPlainObject = require( '@stdlib/assert-is-plain-object' );\n*\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* bool = isPlainObject( null );\n* // returns false\n*/\n\n// MODULES //\n\nvar isPlainObject = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar replace = require( '@stdlib/string-replace' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Returns a function which formats an error message for production.\n*\n* @param {Options} options - function options\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {Function} error formatting function\n*\n* @example\n* var opts = {\n* 'url': 'https://stdlib.io/error-decoder.html'\n* };\n*\n* var fcn = factory( opts );\n* // returns \n*/\nfunction factory( options ) {\n\tvar opts;\n\tvar err;\n\topts = copy( defaults );\n\terr = validate( opts, options );\n\tif ( err ) {\n\t\tthrow err;\n\t}\n\treturn formatProdErrorMessage;\n\n\t/**\n\t* Formats an error message for production.\n\t*\n\t* @private\n\t* @param {string} code - error code\n\t* @param {*} ...args - error message arguments\n\t* @returns {string} formatted error message\n\t*/\n\tfunction formatProdErrorMessage() {\n\t\tvar code = arguments[ 0 ];\n\t\tvar url = opts.url + '?code='+code;\n\t\tvar msg;\n\t\tvar i;\n\t\tfor ( i = 1; i < arguments.length; i++ ) {\n\t\t\turl += '&arg[]=' + encodeURIComponent( arguments[ i ] );\n\t\t}\n\t\tmsg = replace( opts.message, '{{url}}', url );\n\t\tmsg = replace( msg, '{{code}}', code );\n\t\treturn msg;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Format an error message for production.\n*\n* @module @stdlib/error-tools-fmtprodmsg\n*\n* @example\n* var formatProdErrorMessage = require( '@stdlib/error-tools-fmtprodmsg' );\n*\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar formatProdErrorMessage = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( formatProdErrorMessage, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @name formatProdErrorMessage\n* @type {Function}\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\nvar formatProdErrorMessage = factory( defaults );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["defineProperty","Object","has_define_property_support","err","builtin","objectProtoype","prototype","toStr","toString","defineGetter","__defineGetter__","defineSetter","__defineSetter__","lookupGetter","__lookupGetter__","lookupSetter","__lookupSetter__","polyfill","obj","prop","descriptor","hasValue","hasGet","hasSet","call","TypeError","__proto__","value","Error","get","set","require$$1","require$$2","lib","require$$0","main","configurable","enumerable","writable","primitive","FLG","Symbol","hasSymbols","toStringTag","tostring","native_class","v","has","hasOwnProperty","property","toStrTag","hasOwnProp","isOwn","tag","out","valueOf","String","nativeClass","test","object","isPrimitive","isObject","setReadOnly","isString","require$$3","RE_CHARS","str","s","i","length","replace","substring","re","Boolean","isBoolean","codegen","Function","self_1","self","window_1","window","global","module","exports","getThis","Self","Win","Global","arguments","root","nodeList","document","childNodes","typedarray","Int8Array","RE","check_1","reFunctionName","Array","isArray","isObjectLike","predicate","len","arrayfun","_isBuffer","constructor","isBuffer","REGEXP","match","name","ctor","slice","exec","ctorName","typeOf","type","toLowerCase","RegExp","rescape","isFunction","isRegExp","search","newval","Number","isNumber","POSITIVE_INFINITY","NEGATIVE_INFINITY","floor","Math","x","PINF","NINF","isInt","integer","isInteger","isNonNegativeInteger","getProto","getPrototypeOf","proto","reRegExp","isNan","isnan","isCollection","index_of","arr","searchElement","fromIndex","keys","has_arguments_bug","has_builtin","bool","isArguments","bool$8","detect","detect_1","native","propertyIsEnumerable","bool$7","isEnum","hasStringEnumBug","isEnumerableProperty","require$$4","builtin_wrapper","has_enumerable_prototype_bug","has_non_enumerable_properties_bug","is_constructor_prototype","w","indexOf","isConstructorPrototype","EXCLUDED_KEYS","win","bool$4","k","check","hasAutomationEqualityBug","HAS_WINDOW","HAS_ENUM_PROTO_BUG","HAS_NON_ENUM_PROPS_BUG","error","NON_ENUMERABLE","wrapper","skipConstructor","skipPrototype","isFcn","p","push","getOwnPropertyNames","propertyNames","getOwnPropertyDescriptor","propertyDescriptor","desc","Buffer","from","buffer","hasInt8Array","isInt8Array","GlobalInt8Array","INT8_MAX","hasUint8Array","Uint8Array","isUint8Array","GlobalUint8Array","UINT8_MAX","hasUint8ClampedArray","Uint8ClampedArray","isUint8ClampedArray","GlobalUint8ClampedArray","hasInt16Array","Int16Array","isInt16Array","GlobalInt16Array","INT16_MAX","hasUint16Array","Uint16Array","isUint16Array","GlobalUint16Array","UINT16_MAX","hasInt32Array","Int32Array","isInt32Array","GlobalInt32Array","INT32_MAX","hasUint32Array","Uint32Array","isUint32Array","GlobalUint32Array","UINT32_MAX","hasFloat32Array","Float32Array","isFloat32Array","GlobalFloat32Array","hasFloat64Array","Float64Array","isFloat64Array","GlobalFloat64Array","NaN","require$$5","require$$6","require$$7","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","isError","regexp","objectKeys","require$$8","require$$9","require$$10","require$$11","copyBuffer","require$$12","typedArrays","deepCopy","val","copy","cache","refs","level","parent","key","ref","j","tmp","message","stack","code","errno","syscall","copyError","Date","Set","Map","freeze","names","create","isExtensible","preventExtensions","isSealed","seal","isFrozen","cloneInstance","copy_1","objectPrototype","isPrototypeOf","ownProps","validate","opts","options","url","defaults","factory_1","msg","encodeURIComponent","formatProdErrorMessage","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","RangeError","format"],"mappings":";6kBAsBA,ICAIA,EDA0C,mBAA1BC,OAAOD,eAAkCC,OAAOD,eAAiB,KC4BrF,IAAAE,EAbA,WAEC,IAEC,OADAF,EAAgB,GAAI,IAAK,KAClB,EACN,MAAQG,GACT,OAAO,ICiBTC,EALqBH,OAAOD,eC/BxBK,EAAiBJ,OAAOK,UACxBC,EAAQF,EAAeG,SACvBC,EAAeJ,EAAeK,iBAC9BC,EAAeN,EAAeO,iBAC9BC,EAAeR,EAAeS,iBAC9BC,EAAeV,EAAeW,iBAuFlC,IAAAC,EAnDA,SAAyBC,EAAKC,EAAMC,GACnC,IAAId,EACAe,EACAC,EACAC,EAEJ,GAAoB,iBAARL,GAA4B,OAARA,GAAsC,mBAAtBX,EAAMiB,KAAMN,GAC3D,MAAM,IAAIO,UAAW,+DAAiEP,EAAM,MAE7F,GAA2B,iBAAfE,GAA0C,OAAfA,GAAoD,mBAA7Bb,EAAMiB,KAAMJ,GACzE,MAAM,IAAIK,UAAW,oEAAsEL,EAAa,MAyBzG,IAvBAC,EAAa,UAAWD,KAGtBP,EAAaW,KAAMN,EAAKC,IACxBJ,EAAaS,KAAMN,EAAKC,IAGxBb,EAAYY,EAAIQ,UAChBR,EAAIQ,UAAYrB,SAGTa,EAAKC,GACZD,EAAKC,GAASC,EAAWO,MAGzBT,EAAIQ,UAAYpB,GAEhBY,EAAKC,GAASC,EAAWO,OAG3BL,EAAW,QAASF,EACpBG,EAAW,QAASH,EAEfC,IAAcC,GAAUC,GAC5B,MAAM,IAAIK,MAAO,wHASlB,OANKN,GAAUb,GACdA,EAAae,KAAMN,EAAKC,EAAMC,EAAWS,KAErCN,GAAUZ,GACdA,EAAaa,KAAMN,EAAKC,EAAMC,EAAWU,KAEnCZ,GCrEJd,EAAU2B,EACVd,EAAWe,EAefC,EAjB+BC,IASb9B,EAEAa,EC7BdjB,EAAiBkC,EAmCrB,IAAAC,EAZA,SAAmCjB,EAAKC,EAAMQ,GAC7C3B,EAAgBkB,EAAKC,EAAM,CAC1BiB,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,KCJXM,EAL+BC,ECA/B,IAAAK,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCMjB,ICdIa,EDIJ,WACC,MACmB,mBAAXC,QACoB,iBAApBA,OAAQ,OCPPC,GAqBV,ICTAT,EDEA,WACC,OAASO,GAAqC,iBAAvBC,OAAOE,aEf/BC,EALY3C,OAAOK,UAAUE,SCAzBD,EAAQ2B,EAiCZ,IAAAW,EAPA,SAAsBC,GACrB,OAAOvC,EAAMiB,KAAMsB,IC3BhBC,EAAM9C,OAAOK,UAAU0C,eAyC3B,ICjBAf,EDIA,SAAqBN,EAAOsB,GAC3B,OACCtB,SAKMoB,EAAIvB,KAAMG,EAAOsB,IEnCrBC,EAA+B,mBAAXT,OAA0BA,OAAOE,YAAc,GCAnEQ,EAAajB,EACbS,EDIaO,ECHb3C,EAAQyB,EAwDZ,ICpCI5B,EAAU2B,EACVd,EDKJ,SAAsB6B,GACrB,IAAIM,EACAC,EACAC,EAEJ,GAAKR,QACJ,OAAOvC,EAAMiB,KAAMsB,GAEpBO,EAAMP,EAAGH,GACTS,EAAQD,EAAYL,EAAGH,GAGvB,IACCG,EAAGH,QAAgB,EAClB,MAAQxC,GACT,OAAOI,EAAMiB,KAAMsB,GASpB,OAPAQ,EAAM/C,EAAMiB,KAAMsB,GAEbM,EACJN,EAAGH,GAAgBU,SAEZP,EAAGH,GAEJW,GCdRrB,EAjBqBC,IASNjB,EAEAb,EChCXmD,ECDUC,OAAOlD,UAAUiD,QDyB/B,IEvBIE,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADA4B,EAAQ/B,KAAMG,IACP,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB6B,SAGjBhB,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,EAAW9B,EA0Bf,ICSI+B,EAAc5B,EACd6B,EDjBJ,SAAmBpC,GAClB,OAASiC,EAAajC,IAAWkC,EAAUlC,ICkBxCkC,EAAWG,EAKfF,EAAaC,EAAU,cANL/B,GAOlB8B,EAAaC,EAAU,WAAYF,GAKnC,IAAA5B,EAAiB8B,EClDbA,EAAW7B,EAAsC0B,YAKjDK,EAAW,yBAqDf,ICzCAhC,EDIA,SAAkBiC,GACjB,IACIC,EACAC,EAEJ,IAAML,EAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAGrG,GAAkB,MAAbA,EAAK,GAGT,IAAME,EADAF,EAAIG,OACI,EAAGD,GAAK,GACH,MAAbF,EAAKE,GADcA,KAO1B,YAAW,IAANA,GAAgBA,GAAK,EAClBF,EAAII,QAASL,EAAU,SAM/BE,GAHAA,EAAID,EAAIK,UAAW,EAAGH,IAGhBE,QAASL,EAAU,QAGzBC,EAAMA,EAAK,GAAMC,EAAID,EAAIK,UAAWH,KE/CrCI,EALS,ICyBT,IAAAjC,EAPA,SAAoBZ,GACnB,MAA0B,kBAAVA,GCjBbnB,ECDWiE,QAAQnE,UAAUE,SDyBjC,IEvBIiD,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADAnB,EAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAoBhC,GACnB,MAAsB,iBAAVA,IACNA,aAAiB8C,UAGjBjC,EACGkB,EAAM/B,GAEoB,qBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,GAAW9B,EAkCf,ICAI+B,GAAc5B,EACdwC,GDRJ,SAAoB/C,GACnB,OAASiC,EAAajC,IAAWkC,GAAUlC,ICSxCkC,GAAWG,EAKfF,GAAaY,GAAW,cANN1C,GAOlB8B,GAAaY,GAAW,WAAYb,IAKpC,IAAA5B,GAAiByC,GCpCjB,IAAAC,GAPA,WACC,OAAO,IAAIC,SAAU,eAAd,ICFRC,GAL4B,iBAATC,KAAsBA,KAAO,KCKhDC,GAL8B,iBAAXC,OAAwBA,OAAS,6GCAhD9D,GAA0B,iBAAX+D,GAAwBA,GAAS,KAKpDC,OAAOC,QAAUjE,OCLbwD,GAAYxC,GAAuC0B,YACnDwB,GAAUrD,GACVsD,GAAOrD,GACPsD,GAAMtB,GACNuB,sCAkDJ,IAAApD,GA7BA,SAAoBwC,GACnB,GAAKa,UAAUnB,OAAS,CACvB,IAAMK,GAAWC,GAChB,MAAM,IAAIlD,UAAW,+DAA+DkD,EAAQ,MAE7F,GAAKA,EACJ,OAAOS,KAKT,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,MAAM,IAAI3D,MAAO,uDC3Cd6D,GCOYvD,KDNZwD,GAAWD,GAAKE,UAAYF,GAAKE,SAASC,WER1CC,GAAaC,UCEbC,GAAK7D,EACLwD,GHUaA,GGTbG,GDCaA,GC6BjB,IAAAG,GAnBA,WACC,MAEe,mBAAPD,IAGe,iBAAfF,IAGa,mBAAbH,ICST,IAAAvD,GAPA,WACC,MAAO,2BCEJ8D,GAAiBlE,GADHG,EAOL+D,GAAgB,SCjCR/D,MDsCrB,IAAAD,GAAiBgE,GEtCbxC,GAAcvB,EAwClB,ICpBAD,GDWKiE,MAAMC,QACND,MAAMC,QARX,SAAkBxE,GACjB,MAAkC,mBAAzB8B,GAAa9B,IEzBnBwE,GAAUjE,GC0Bd,ICGIkE,GDbJ,SAAuBzE,GACtB,OACW,OAAVA,GACiB,iBAAVA,GCQSO,EAOLkE,GAAc,oBFR3B,SAAmBC,GAClB,GAA0B,mBAAdA,EACX,MAAM,IAAI5E,UAAW,sDAAwD4E,EAAY,MAE1F,OASA,SAAgB1E,GACf,IAAI2E,EACAlC,EACJ,IAAM+B,GAASxE,GACd,OAAO,EAGR,GAAa,KADb2E,EAAM3E,EAAM0C,QAEX,OAAO,EAER,IAAMD,EAAI,EAAGA,EAAIkC,EAAKlC,IACrB,IAAiC,IAA5BiC,EAAW1E,EAAOyC,IACtB,OAAO,EAGT,OAAO,GEpBuCmC,CAAUH,KAK1D,IAAAnE,GAAiBmE,GCvCbA,GAAelE,GA+CnB,IC3BAD,GDOA,SAAmBN,GAClB,OACCyE,GAAczE,KAGbA,EAAM6E,WAEL7E,EAAM8E,aAGgC,mBAA/B9E,EAAM8E,YAAYC,UACzB/E,EAAM8E,YAAYC,SAAU/E,KEtC5B8B,GAAcvB,EACd6D,GAAKhE,GAA0C4E,OAC/CD,GAAW1E,GAuDf,IAAAG,GAxBA,SAA0BW,GACzB,IAAI8D,EACAC,EACAC,EAEJ,IAAe,YADfD,EAAOpD,GAAaX,GAAIiE,MAAO,GAAI,KACC,UAATF,IAAqB/D,EAAE2D,YAAc,CAE/D,GAA0B,iBAD1BK,EAAOhE,EAAE2D,aACQI,KAChB,OAAOC,EAAKD,KAGb,GADAD,EAAQb,GAAGiB,KAAMF,EAAKtG,YAErB,OAAOoG,EAAO,GAGhB,OAAKF,GAAU5D,GACP,SAED+D,GCnDJI,GCkBkB/E,GDmCtB,IErDI+E,GDkBkB/E,GCAtB,ICFIgF,GHkBJ,SAAiBpE,GAChB,IAAIqE,EAGJ,OAAW,OAANrE,EACG,OAKM,YAHdqE,SAAcrE,GAINmE,GAAUnE,GAAIsE,cAEfD,GG9BJlG,GDNJ,SAAiB6B,GAChB,OAAOmE,GAAUnE,GAAIsE,eCetBnF,GAZkBC,KAOajB,GAAWiG,GCtBtCA,GAAShF,GA2Bb,ICNAD,GDFA,SAAqBN,GAEpB,MAA6B,aAApBuF,GAAQvF,IErBdqF,GCFOK,OAAO/G,UAAU0G,KD0B5B,IEvBIvD,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADAqF,GAAKxF,KAAMG,IACJ,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBN,IA0CrB,IC1CIoF,GAAUpF,EACVqF,GAAaxF,GACbgC,GAAW/B,EAAsC4B,YACjD4D,GDuBJ,SAAmB7F,GAClB,MAAsB,iBAAVA,IACNA,aAAiB0F,SAGjB7E,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MC2BxB,ICvCAM,GDmBA,SAAkBiC,EAAKuD,EAAQC,GAC9B,IAAM3D,GAAUG,GACf,MAAM,IAAIzC,UAAW,wEAA0EyC,EAAM,MAEtG,GAAKH,GAAU0D,GACdA,EAASH,GAASG,GAClBA,EAAS,IAAIJ,OAAQI,EAAQ,UAEzB,IAAMD,GAAUC,GACpB,MAAM,IAAIhG,UAAW,+FAAiGgG,EAAS,MAEhI,IAAM1D,GAAU2D,KAAaH,GAAYG,GACxC,MAAM,IAAIjG,UAAW,gGAAkGiG,EAAS,MAEjI,OAAOxD,EAAII,QAASmD,EAAQC,IEhC7B,IAAAnF,GAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCAjBM,GCjBiB0F,OCAbnH,GCAS0B,GAMS5B,UAAUE,SDkBhC,IEvBIiD,GAAc1B,EACd4F,GAAS3F,GACT0B,GFSJ,SAAe/B,GACd,IAEC,OADAnB,GAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IETLqC,GARiBN,IA2CrB,IAAAyB,GAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiBgG,KAGjBnF,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MCnCpBiC,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd0F,GDfJ,SAAmBjG,GAClB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa8D,GAAU,cANL5F,IAOlB8B,GAAa8D,GAAU,WAAY/D,IAKnC,IAAA5B,GAAiB2F,GCvBjB3F,GALmB0F,OAAOE,kBCS1B5F,GA1BaC,GAqBa4F,kBChCtBC,GCsBQC,KAAKD,MDIjB,IENA9F,GFDA,SAAoBgG,GACnB,OAAQF,GAAME,KAAOA,GGpBlBC,GAAOhG,GACPiG,GAAOpG,GACPqG,GAAQpG,GAuBZ,IAAAqG,GAXA,SAAoB1G,GACnB,OACCA,EAAQuG,IACRvG,EAAQwG,IACRC,GAAOzG,IClBLiG,GAAW1F,GAAsC0B,YACjDwE,GAAQrG,GA6BZ,IAAAQ,GAVA,SAAoBZ,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,ICvBLiG,GAAW1F,GAAsC2B,SACjDuE,GAAQrG,GA6BZ,IAAA4B,GAVA,SAAoBhC,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICMI+B,GAAc5B,EACdoG,GDdJ,SAAoB3G,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICexCkC,GAAWG,GAKfF,GAAawE,GAAW,cANNtG,IAOlB8B,GAAawE,GAAW,WAAYzE,IAKpC,IAAA5B,GAAiBqG,GCvDbA,GAAYpG,GAAuC0B,YA6BvD,IAAArB,GAVA,SAA+BZ,GAC9B,OACC2G,GAAW3G,IACXA,GAAS,GCtBP2G,GAAYpG,GAAuC2B,SA6BvD,IAAAF,GAVA,SAA+BhC,GAC9B,OACC2G,GAAW3G,IACXA,EAAM4B,WAAa,GCtBjBK,GAAc1B,GACd2B,GAAW9B,GAsCf,ICGI+B,GAAc5B,EACdqG,GDXJ,SAA+B5G,GAC9B,OAASiC,GAAajC,IAAWkC,GAAUlC,ICYxCkC,GAAWG,GAKfF,GAAayE,GAAsB,cANjBvG,IAOlB8B,GAAayE,GAAsB,WAAY1E,IAK/C,IAAA5B,GAAiBsG,GCxDbC,GAAWvI,OAAOwI,eCatB,IAAAC,GARA,SAAmBxH,GAElB,OAAOA,EAAIQ,WCPR+B,GAAcvB,EACdsG,GAAWzG,GA+Bf,IAAAd,GAnBA,SAAyBC,GACxB,IAAIwH,EAAQF,GAAUtH,GACtB,OAAKwH,GAAmB,OAAVA,EACNA,EAEgC,sBAAnCjF,GAAavC,EAAIuF,aAEdvF,EAAIuF,YAAYnG,UAEnBY,aAAejB,OACZA,OAAOK,UAGR,MCzBJF,GHIaoI,GGHbvH,GAAWe,GCFXwG,GDAatG,GAQAjC,OAAOwI,gBACZrI,GAEAa,GCoBZ,ICdAgB,GDFA,SAAyBN,GACxB,OACCA,QAGO,MAGRA,EAAQ1B,OAAQ0B,GAET6G,GAAU7G,KEzBd8G,GAAiBvG,GACjBuB,GAAc1B,EAwClB,ICrBAE,GDAA,SAAkBN,GACjB,GAAsB,iBAAVA,GAAgC,OAAVA,EACjC,OAAO,EAGR,GAAKA,aAAiBC,MACrB,OAAO,EAGR,KAAQD,GAAQ,CACf,GAA8B,mBAAzB8B,GAAa9B,GACjB,OAAO,EAERA,EAAQ8G,GAAgB9G,GAEzB,OAAO,GEdR,IAAAQ,GAPA,WACC,MAAO,oCCWJwG,GAAW5G,GADGG,EAOLyG,GAAU,SChCRzG,UCAX6B,GAAW7B,EAAsC0B,YACjD+E,GFyCaA,GEXjB,ICdA1G,GDAA,SAAuBiC,GACtB,IAAMH,GAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAMrG,OAHAA,EAAMyE,KAAW3B,KAAM9C,IAGN,IAAImD,OAAQnD,EAAI,GAAIA,EAAI,IAAO,MEJjD,IAAA/B,GAPA,SAAgB8F,GACf,OAASA,GAAMA,GCfZL,GAAW1F,GAAsC0B,YACjDgF,GCcQ1G,GDmBZ,IAAAK,GAVA,SAAgBZ,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,IE3BLiG,GAAW1F,GAAsC2B,SACjD+E,GDcQ1G,GCeZ,IAAAyB,GAVA,SAAgBhC,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd2G,GDfJ,SAAgBlH,GACf,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa+E,GAAO,cANF7G,IAOlB8B,GAAa+E,GAAO,WAAYhF,IAKhC,IAAA5B,GAAiB4G,GCxDbP,GAAYpG,GAkChB,IClCI2G,GAAQ3G,GACR4G,GDmBJ,SAAuBnH,GACtB,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QENqB,kBDnBzBN,GAAW/B,EAAsC4B,YACjD0E,GAAYtE,GAAuCJ,YA0GvD,IAAAmF,GAhDA,SAAkBC,EAAKC,EAAeC,GACrC,IAAI5C,EACAlC,EACJ,IAAM0E,GAAcE,KAAUjF,GAAUiF,GACvC,MAAM,IAAIvH,UAAW,0EAA4EuH,EAAM,MAGxG,GAAa,KADb1C,EAAM0C,EAAI3E,QAET,OAAQ,EAET,GAA0B,IAArBmB,UAAUnB,OAAe,CAC7B,IAAMiE,GAAWY,GAChB,MAAM,IAAIzH,UAAW,6DAA+DyH,EAAY,MAEjG,GAAKA,GAAa,EAAI,CACrB,GAAKA,GAAa5C,EACjB,OAAQ,EAETlC,EAAI8E,OAEJ9E,EAAIkC,EAAM4C,GACD,IACR9E,EAAI,QAINA,EAAI,EAGL,GAAKyE,GAAOI,IACX,KAAQ7E,EAAIkC,EAAKlC,IAChB,GAAKyE,GAAOG,EAAI5E,IACf,OAAOA,OAIT,KAAQA,EAAIkC,EAAKlC,IAChB,GAAK4E,EAAK5E,KAAQ6E,EACjB,OAAO7E,EAIV,OAAQ,GErDTnC,GALcC,GClBd,IAAA9B,GAPA,SAAeuB,GACd,OAAO1B,OAAOkJ,KAAMlJ,OAAQ0B,KCrBzBwH,GAAOjH,GAmCX,IAAAkH,GAPA,WACC,OAlBD,WACC,OAA8C,KAArCD,GAAM3D,YAAe,IAAKnB,OAiB5BX,CAAM,EAAG,ICxBjB2F,QALoC,IAAhBpJ,OAAOkJ,KCAvB1F,GAAcvB,EA+BlB,IC1BIoH,GD0BJnH,GAPA,SAAsBR,GACrB,MAAkC,uBAAzB8B,GAAa9B,ICzBnB4H,GAAcrH,GA2BdsH,GAPJ,WACC,OAAOD,GAAa/D,WAMdiE,GAKP,IC3BIH,GD2BJI,GAAiBJ,GEDjBK,GAL2B1J,OAAOK,UAAUsJ,qBDHxCC,IAvBS3H,GAiBGV,KAAM,OAAQ,KAW9B,IE5BIuC,GAAW7B,EACX2G,GAAQ9G,GAAmC6B,YAC3C0E,GAAYtG,GAAuC4B,YACnDkG,GAAS9F,GACT+F,GFwBaT,GE6BjB,IAAAnH,GAzBA,SAA+BR,EAAOsB,GACrC,IAAIqG,EACJ,OACC3H,YAKD2H,EAAOQ,GAAOtI,KAAMG,EAAOsB,KACb8G,IAAoBhG,GAAUpC,IAIzCkH,GAFF5F,GAAYA,IAGXqF,GAAWrF,IACXA,GAAY,GACZA,EAAWtB,EAAM0C,OAGZiF,IC3BRrH,GAL2BC,GCnBvBiB,GAAajB,EACb8H,GAAuBjI,GACvBoE,GAAUnE,GACVsG,GAAYtE,GCiChB,IAAA/B,GAjBwBC,GACbH,GDQX,SAAsBJ,GACrB,OACW,OAAVA,GACiB,iBAAVA,IACNwE,GAASxE,IACc,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QAhCS4F,YAiCf9G,GAAYxB,EAAO,YAClBqI,GAAsBrI,EAAO,WEtC5B4H,GAAcrH,GACd9B,GAAU2B,GAKVgF,GAAQb,MAAM5F,UAAUyG,MA+B5B,IAAAmD,GAVA,SAAevI,GACd,OAAK4H,GAAa5H,GACVvB,GAAS2G,GAAMvF,KAAMG,IAEtBvB,GAASuB,ICnBjB,ICAAwI,GAZ2BjI,IDK3B,cCEuC,aCWvCkI,IAlB2BlI,GAKjB,CACT1B,SAAY,MAO0B,YCCvC,ICJI8I,GDIJe,GAPA,SAAiC1I,GAChC,OAASA,EAAM8E,aAAe9E,EAAM8E,YAAYnG,YAAcqB,GER3D2I,GAAwB,oBAAXtF,YAA2B,EAASA,ODAjD7B,GAAajB,EACbqI,GAAUxI,GACVmF,GAASlF,GACTwI,GAAyBxG,GACzByG,wPACAC,GCAaJ,GD2CbK,GAzBJ,WACC,IAAIC,EACJ,GAAuB,cAAlB1D,GAAQwD,IACZ,OAAO,EAER,IAAME,KAAKF,GACV,KAEmC,IAAjCH,GAASE,GAAeG,IACxBzH,GAAYuH,GAAKE,IACJ,OAAbF,GAAKE,IACkB,WAAvB1D,GAAQwD,GAAKE,KAEbJ,GAAwBE,GAAKE,IAE7B,MAAQzK,GACT,OAAO,EAGT,OAAO,EAMD0K,GAKP,IErDIvB,GAA2B,oBAAXtE,OCAhB8F,GHqDaxB,GGpDbkB,GAAyBzI,GACzBgJ,GDGazB,GCuBjB,IC5BIlD,GAAelE,GACfiB,GAAapB,EACbwH,GAAcvH,GACdgJ,GAAqBhH,GACrBiH,GAAyBhB,GACzBO,GDSJ,SAAkB7I,GACjB,IAAoB,IAAfoJ,KAAyBD,GAC7B,OAAON,GAAwB7I,GAEhC,IACC,OAAO6I,GAAwB7I,GAC9B,MAAQuJ,GACT,OAAO,ICfLC,iHAyEJ,IC7EI/K,GAAU4B,GACVoJ,GAAUpH,GACV/C,GDuBJ,SAAeU,GACd,IAAI0J,EACAC,EACAC,EACAjI,EACAsH,EACAY,EACApH,EAGJ,GADAd,EAAM,GACDiG,GAAa5H,GAAU,CAE3B,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,YAGb,OAAO8C,EAER,GAAsB,iBAAV3B,GAEX,GAAKA,EAAM0C,OAAS,IAAMlB,GAAYxB,EAAO,KAC5C,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,gBAGR,CAEN,IAAe,KADf+K,EAA2B,mBAAV5J,KACQyE,GAAczE,GACtC,OAAO2B,EAERgI,EAAkBN,IAAsBO,EAEzC,IAAMX,KAAKjJ,EACF2J,GAAuB,cAANV,IAAuBzH,GAAYxB,EAAOiJ,IAClEtH,EAAImI,KAAMjI,OAAQoH,IAGpB,GAAKK,GAEJ,IADAI,EAAkBb,GAAwB7I,GACpCyC,EAAI,EAAGA,EAAI+G,GAAe9G,OAAQD,IACvCoH,EAAIL,GAAgB/G,GACZiH,GAAyB,gBAANG,IAAyBrI,GAAYxB,EAAO6J,IACtElI,EAAImI,KAAMjI,OAAQgI,IAIrB,OAAOlI,GEnDRrB,GDrBkBF,GADIG,KA6BbkJ,GAEAhL,GAGDa,GE7BRoI,QALmD,IAA/BpJ,OAAOyL,oBCAvBC,GAAgB1L,OAAOyL,oBAgC3B,IChCIvC,GAAOjH,GCgCX,IAAAD,GAjBkBC,GFUlB,SAA8BP,GAC7B,OAAOgK,GAAe1L,OAAQ0B,KCA/B,SAA8BA,GAC7B,OAAOwH,GAAMlJ,OAAQ0B,KEtBtB0H,QALwD,IAApCpJ,OAAO2L,yBCAvBC,GAAqB5L,OAAO2L,yBAuChC,ICvCIzI,GAAajB,ECkCjB,IAAAD,GAjBkBC,GFUlB,SAAmCP,EAAOsB,GACzC,IAAI6I,EACJ,OAAKnK,cAIa,KADlBmK,EAAOD,GAAoBlK,EAAOsB,IAF1B,KAG4B6I,GCLrC,SAAmCnK,EAAOsB,GACzC,OAAKE,GAAYxB,EAAOsB,GAChB,CACNb,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,EAAOsB,IAGX,iyqBEvBR,ICDId,uJCb2B4J,ODc3B9K,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GAjB2BC,KASnBC,GAEAlB,GEjBJqI,GANapH,GACJH,GAKiBiK,MCN1BtF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAI,GAVA,SAAqB8J,GACpB,IAAMvF,GAAUuF,GACf,MAAM,IAAIxK,UAAW,oDAAsDwK,EAAS,KAErF,OAAOF,GAAOC,KAAMC,IC1BjBvF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAd,GAVA,SAAqBgL,GACpB,IAAMvF,GAAUuF,GACf,MAAM,IAAIxK,UAAW,oDAAsDwK,EAAS,KAErF,OAAO,IAAIF,GAAQE,ICOpBhK,GHtBiBqH,GGMNvH,GACIC,GClBXyB,GAAcvB,EAKdgK,GAAsC,mBAAdpG,UA6B5B,IClCI3D,GAA8B,mBAAd2D,UAA6BA,UAAY,KCAzDqG,GFwBJ,SAAsBxK,GACrB,OACGuK,IAAgBvK,aAAiBmE,WACV,uBAAzBrC,GAAa9B,IExBXyK,GDEajK,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAgC,mBAApBoD,GACX,OAAO,EAGR,IACCpD,EAAM,IAAIoD,GAAiB,CAAE,EAAG,MAAO,KAAMC,MAC7C/C,EACC6C,GAAanD,IACA,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEO,MDDZA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb8B,mBAAd0F,UAA6BA,eAAY,EDczD7E,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB0BC,KFSlB9B,GAEAa,GGvBJwC,GAAcvB,EAKdoK,GAAwC,mBAAfC,WA6B7B,IClCIpK,GAA+B,mBAAfoK,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuB7K,GACtB,OACG2K,IAAiB3K,aAAiB4K,YACX,wBAAzB9I,GAAa9B,IEzBX8K,GDGatK,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArByD,GACX,OAAO,EAGR,IAECzD,EAAM,IAAIyD,GADVzD,EAAM,CAAE,EAAG,MAAO,KAAM0D,IAAaA,MAErCpD,EACCkD,GAAcxD,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ0D,MAAb1D,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCb+B,mBAAfmM,WAA8BA,gBAAa,EDc3DtL,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdyK,GAAsD,mBAAtBC,kBA6BpC,IClCIzK,GAAsC,mBAAtByK,kBAAqCA,kBAAoB,KCAzEC,GFwBJ,SAA8BlL,GAC7B,OACGgL,IAAwBhL,aAAiBiL,mBAClB,+BAAzBnJ,GAAa9B,IE1BXmL,GDIa3K,GCuCjB,IAAAA,GA7BA,WACC,IAAImH,EACAN,EAEJ,GAAwC,mBAA5B8D,GACX,OAAO,EAGR,IACC9D,EAAM,IAAI8D,GAAyB,EAAG,EAAG,EAAG,EAAG,KAAM,KAAM,IAAK,MAChExD,EACCuD,GAAqB7D,IACR,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,MAAbA,EAAK,IACQ,MAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbsC,mBAAtBwM,kBAAqCA,uBAAoB,EDczE3L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjBkCC,KFS1B9B,GAEAa,GGvBJwC,GAAcvB,EAKd6K,GAAwC,mBAAfC,WA6B7B,IClCI7K,GAA+B,mBAAf6K,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBtL,GACtB,OACGoL,IAAiBpL,aAAiBqL,YACX,wBAAzBvJ,GAAa9B,IExBXuL,GDEa/K,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArBkE,GACX,OAAO,EAGR,IACClE,EAAM,IAAIkE,GAAkB,CAAE,EAAG,MAAO,KAAMC,QAC9C7D,EACC2D,GAAcjE,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,QDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAf4M,WAA8BA,gBAAa,EDc3D/L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdkL,GAA0C,mBAAhBC,YA6B9B,IClCIlL,GAAgC,mBAAhBkL,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwB3L,GACvB,OACGyL,IAAkBzL,aAAiB0L,aACZ,yBAAzB5J,GAAa9B,IEzBX4L,GDGapL,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBuE,GACX,OAAO,EAGR,IAECvE,EAAM,IAAIuE,GADVvE,EAAM,CAAE,EAAG,MAAO,KAAMwE,MAAcA,QAEtClE,EACCgE,GAAetE,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQwE,QAAbxE,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhBiN,YAA+BA,iBAAc,EDc7DpM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKduL,GAAwC,mBAAfC,WA6B7B,IClCIvL,GAA+B,mBAAfuL,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBhM,GACtB,OACG8L,IAAiB9L,aAAiB+L,YACX,wBAAzBjK,GAAa9B,IExBXiM,GDEazL,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB4E,GACX,OAAO,EAGR,IACC5E,EAAM,IAAI4E,GAAkB,CAAE,EAAG,MAAO,KAAMC,aAC9CvE,EACCqE,GAAc3E,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,aDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAfsN,WAA8BA,gBAAa,EDc3DzM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd4L,GAA0C,mBAAhBC,YA6B9B,IClCI5L,GAAgC,mBAAhB4L,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwBrM,GACvB,OACGmM,IAAkBnM,aAAiBoM,aACZ,yBAAzBtK,GAAa9B,IEzBXsM,GDGa9L,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBiF,GACX,OAAO,EAGR,IAECjF,EAAM,IAAIiF,GADVjF,EAAM,CAAE,EAAG,MAAO,KAAMkF,WAAcA,aAEtC5E,EACC0E,GAAehF,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQkF,aAAblF,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhB2N,YAA+BA,iBAAc,EDc7D9M,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdiM,GAA4C,mBAAjBC,aA6B/B,IClCIjM,GAAiC,mBAAjBiM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB1M,GACxB,OACGwM,IAAmBxM,aAAiByM,cACb,0BAAzB3K,GAAa9B,IE1BXuG,GAAOnG,GACPuM,GDGanM,GCqCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvBsF,GACX,OAAO,EAGR,IACCtF,EAAM,IAAIsF,GAAoB,CAAE,EAAK,MAAO,KAAM,OAClDhF,EACC+E,GAAgBrF,IACH,IAAbA,EAAK,IACQ,oBAAbA,EAAK,KACS,oBAAdA,EAAK,IACLA,EAAK,KAAQd,GAEb,MAAQ/H,GACTmJ,GAAO,EAER,OAAOA,GCtBR,ICDIlJ,GCbiC,mBAAjBgO,aAAgCA,kBAAe,EDc/DnN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB6BC,KFSrB9B,GAEAa,GGvBJwC,GAAcvB,EAKdqM,GAA4C,mBAAjBC,aA6B/B,IClCIrM,GAAiC,mBAAjBqM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB9M,GACxB,OACG4M,IAAmB5M,aAAiB6M,cACb,0BAAzB/K,GAAa9B,IE1BX+M,GDIavM,GCoCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvB0F,GACX,OAAO,EAGR,IACC1F,EAAM,IAAI0F,GAAoB,CAAE,EAAK,MAAO,KAAMC,MAClDrF,EACCmF,GAAgBzF,IACH,IAAbA,EAAK,IACQ,OAAbA,EAAK,KACS,OAAdA,EAAK,IACLA,EAAK,IAAQA,EAAK,GAElB,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCrBR,ICKIxC,GANA1G,GCbiC,mBAAjBoO,aAAgCA,kBAAe,EDc/DvN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCajBkF,GET4B5E,KFSrB9B,GAEAa,GAMR,IG7BI6E,GAAY5D,GACZqK,GAAaxK,GACb6K,GAAoB5K,GACpBgL,GAAahJ,GACbqJ,GAAcpD,GACdyD,GAAakB,GACbb,GAAcc,GACdT,GAAeU,GACfN,GHqBa1H,GGJjB,SAASiI,GAAW/F,GACnB,OAAO,IAAIlD,GAAWkD,GAUvB,SAASgG,GAAYhG,GACpB,OAAO,IAAIuD,GAAYvD,GAUxB,SAASiG,GAAmBjG,GAC3B,OAAO,IAAI4D,GAAmB5D,GAU/B,SAASkG,GAAYlG,GACpB,OAAO,IAAIgE,GAAYhE,GAUxB,SAASmG,GAAanG,GACrB,OAAO,IAAIqE,GAAarE,GAUzB,SAASoG,GAAYpG,GACpB,OAAO,IAAI0E,GAAY1E,GAUxB,SAASqG,GAAarG,GACrB,OAAO,IAAI+E,GAAa/E,GAUzB,SAASsG,GAActG,GACtB,OAAO,IAAIoF,GAAcpF,GAU1B,SAASuG,GAAcvG,GACtB,OAAO,IAAIwF,GAAcxF,GAgC1B,IClJI7F,GAAajB,EACbiE,GAAUpE,GACV2E,GAAW1E,GACXwN,GAAUxL,GACVkD,GAAS+C,GACTwF,GAASb,GACTrE,GAAUsE,GACVa,GAAaZ,GACbnD,GAAgBgE,GAChB9D,GAAqB+D,GACrBnH,GAAiBoH,GACjB7P,GAAiB8P,EACjBC,GAAaC,GACbC,GD+GO,CACTlB,UAAaA,GACbC,WAAcA,GACdC,kBAAqBA,GACrBC,WAAcA,GACdC,YAAeA,GACfC,WAAcA,GACdC,YAAeA,GACfC,aAAgBA,GAChBC,aAAgBA,ICQlB,SAASW,GAAUC,EAAKC,EAAMC,EAAOC,EAAMC,GAC1C,IAAIC,EACArH,EACAtC,EACAiF,EACAhF,EACA2J,EACAC,EACAzI,EACA7D,EACAuM,EAKJ,GAHAJ,GAAS,EAIO,iBAARJ,GACC,OAARA,EAEA,OAAOA,EAER,GAAKzJ,GAAUyJ,GACd,OAAOJ,GAAYI,GAEpB,GAAKX,GAASW,GACb,OAnFF,SAAoBjF,GACnB,IAEI/B,EACA2C,EACA8E,EACAH,EACAtQ,EACAiE,EAPAiM,EAAQ,GACRC,EAAO,GA8BX,IArBAnQ,EAAM,IAAI+K,EAAMzE,YAAayE,EAAM2F,SAEnCR,EAAM5E,KAAMP,GACZoF,EAAK7E,KAAMtL,GAGN+K,EAAM4F,QACV3Q,EAAI2Q,MAAQ5F,EAAM4F,OAGd5F,EAAM6F,OACV5Q,EAAI4Q,KAAO7F,EAAM6F,MAEb7F,EAAM8F,QACV7Q,EAAI6Q,MAAQ9F,EAAM8F,OAEd9F,EAAM+F,UACV9Q,EAAI8Q,QAAU/F,EAAM+F,SAGrB9H,EAAOuG,GAAYxE,GACb9G,EAAI,EAAGA,EAAI+E,EAAK9E,OAAQD,IAC7BqM,EAAMtH,EAAM/E,GACZ0H,EAAOD,GAAoBX,EAAOuF,GAC7BtN,GAAY2I,EAAM,WACtB8E,EAAQzK,GAAS+E,EAAOuF,IAAY,GAAK,GACzC3E,EAAKnK,MAAQuO,GAAUhF,EAAOuF,GAAOG,EAAKP,EAAOC,GAAO,IAEzDtQ,GAAgBG,EAAKsQ,EAAK3E,GAE3B,OAAO3L,EA0CC+Q,CAAWf,GAKnB,GAAc,UAFdtJ,EAAOK,GAAQiJ,IAGd,OAAO,IAAIgB,MAAOhB,GAEnB,GAAc,WAATtJ,EACJ,OAAO4I,GAAQU,EAAI3P,YAEpB,GAAc,QAATqG,EACJ,OAAO,IAAIuK,IAAKjB,GAEjB,GAAc,QAATtJ,EACJ,OAAO,IAAIwK,IAAKlB,GAEjB,GACU,WAATtJ,GACS,YAATA,GACS,WAATA,EAGA,OAAOsJ,EAAI5M,UAGZ,GADAuD,EAAOmJ,GAAapJ,GAEnB,OAAOC,EAAMqJ,GAGd,GACU,UAATtJ,GACS,WAATA,EAGA,MAA8B,mBAAlB5G,OAAOqR,OA1KrB,SAAwBnB,GACvB,IAAIE,EACAkB,EACA1K,EACAyJ,EACAxE,EACA8E,EACAF,EACAtM,EAUJ,IARAiM,EAAQ,GACRC,EAAO,GAEPI,EAAMzQ,OAAOuR,OAAQ/I,GAAgB0H,IACrCE,EAAM5E,KAAM0E,GACZG,EAAK7E,KAAMiF,GAEXa,EAAQ5F,GAAewE,GACjB/L,EAAI,EAAGA,EAAImN,EAAMlN,OAAQD,IAC9ByC,EAAO0K,EAAOnN,GACd0H,EAAOD,GAAoBsE,EAAKtJ,GAC3B1D,GAAY2I,EAAM,WACtB8E,EAAQzK,GAASgK,EAAItJ,IAAY,GAAK,GACtCiF,EAAKnK,MAAQuO,GAAUC,EAAItJ,GAAO+J,EAAKP,EAAOC,GAAO,IAEtDtQ,GAAgB0Q,EAAK7J,EAAMiF,GAW5B,OATM7L,OAAOwR,aAActB,IAC1BlQ,OAAOyR,kBAAmBhB,GAEtBzQ,OAAO0R,SAAUxB,IACrBlQ,OAAO2R,KAAMlB,GAETzQ,OAAO4R,SAAU1B,IACrBlQ,OAAOqR,OAAQZ,GAETA,EAuIEoB,CAAe3B,GAEhB,GAIR,GADAhH,EAAOuG,GAAYS,GACdI,EAAQ,EAEZ,IADAC,EAAS3J,EACH8J,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAE7B1I,EAAIkI,EADJM,EAAMtH,EAAMwH,IAIZ9J,EAAOK,GAAQe,GAED,iBAANA,GACD,OAANA,GAEU,UAATpB,GACS,WAATA,GAEDH,GAAUuB,GAEM,WAAXuI,GACJ1E,EAAOD,GAAoBsE,EAAKM,GAC3BtN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQuO,GAAUjI,IAExBjI,GAAgBoQ,EAAMK,EAAK3E,IAE3BsE,EAAMK,GAAQP,GAAUjI,IAMd,KADZ7D,EAAImG,GAAS8F,EAAOpI,KAMpByI,EAAQvK,GAAS8B,GAAQ,IAAI/B,MAAO+B,EAAE5D,QAAW,GACjDgM,EAAM5E,KAAMxD,GACZqI,EAAK7E,KAAMiF,GACK,UAAXF,EACJJ,EAAMK,GAAQP,GAAUjI,EAAGyI,EAAKL,EAAOC,EAAMC,IAE7CzE,EAAOD,GAAoBsE,EAAKM,GAC3BtN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQuO,GAAUjI,EAAGyI,EAAKL,EAAOC,EAAMC,IAE7CvQ,GAAgBoQ,EAAMK,EAAK3E,KAd3BsE,EAAMK,GAAQH,EAAMlM,QAiBhB,GAAc,UAATyC,EACX,IAAM8J,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAE7BP,EADAK,EAAMtH,EAAMwH,IACER,EAAKM,QAGpB,IAAME,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAC7BF,EAAMtH,EAAMwH,GACZ7E,EAAOD,GAAoBsE,EAAKM,GAChCzQ,GAAgBoQ,EAAMK,EAAK3E,GAY7B,OATM7L,OAAOwR,aAActB,IAC1BlQ,OAAOyR,kBAAmBtB,GAEtBnQ,OAAO0R,SAAUxB,IACrBlQ,OAAO2R,KAAMxB,GAETnQ,OAAO4R,SAAU1B,IACrBlQ,OAAOqR,OAAQlB,GAETA,EAMR,IC3RIjK,GAAUjE,GACVqG,GAAuBxG,GAAmD6B,YAC1EsE,GAAOlG,GACPkO,GDwRaA,GCtOjB,IAAA6B,GAnBA,SAAepQ,EAAO4O,GACrB,IAAIjN,EACJ,GAAKkC,UAAUnB,OAAS,EAAI,CAC3B,IAAMkE,GAAsBgI,GAC3B,MAAM,IAAI9O,UAAW,oEAAsE8O,EAAQ,MAEpG,GAAe,IAAVA,EACJ,OAAO5O,OAGR4O,EAAQrI,GAGT,OADA5E,EAAQ6C,GAASxE,GAAY,IAAIuE,MAAOvE,EAAM0C,QAAW,GAClD6L,GAAUvO,EAAO2B,EAAK,CAAC3B,GAAQ,CAAC2B,GAAMiN,ICd9CtO,GALWC,GC5BPiE,GAAUjE,GA8Bd,IC9BI2B,GDmBJ,SAAmBlC,GAClB,MACkB,iBAAVA,GACG,OAAVA,IACCwE,GAASxE,ICtBR4F,GAAaxF,GACb0G,GAAiBzG,GACjBmB,GAAaa,EACbP,GAAcwG,EAKd+H,GAAkB/R,OAAOK,UAgF7B,IAAA6B,GAvCA,SAAwBR,GACvB,IAAI+G,EAGJ,QAAM7E,GAAUlC,OAIhB+G,EAAQD,GAAgB9G,MAOtBwB,GAAYxB,EAAO,gBAGpBwB,GAAYuF,EAAO,gBACnBnB,GAAYmB,EAAMjC,cACmB,sBAArChD,GAAaiF,EAAMjC,cAGnBtD,GAAYuF,EAAO,kBACnBnB,GAAYmB,EAAMuJ,iBAIjBvJ,IAAUsJ,IAzDb,SAAmB9Q,GAClB,IAAIuP,EAGJ,IAAMA,KAAOvP,EACZ,IAAMiC,GAAYjC,EAAKuP,GACtB,OAAO,EAGT,OAAO,EAmDLyB,CAAUvQ,MCjFTkC,GCegB3B,GDdhBiB,GAAapB,EACbgC,GAAW/B,EAAsC4B,YAqCrD,wJEvCIU,GAAUpC,GACVkO,GAAOrO,GACPoQ,GFeJ,SAAmBC,EAAMC,GACxB,OAAMxO,GAAUwO,GAGXlP,GAAYkP,EAAS,SACzBD,EAAKE,IAAMD,EAAQC,KACbvO,GAAUqO,EAAKE,MACb,IAAI7Q,UAAW,qEAAuE2Q,EAAKE,IAAM,MAGrGnP,GAAYkP,EAAS,aACzBD,EAAKvB,QAAUwB,EAAQxB,SACjB9M,GAAUqO,EAAKvB,UACb,IAAIpP,UAAW,yEAA2E2Q,EAAKvB,QAAU,MAG3G,KAdC,IAAIpP,UAAW,iEAAmE4Q,EAAU,OEhBjGE,GAAWvO,GAwDf,IAAAwO,GAnCA,SAAkBH,GACjB,IAAID,EACAjS,EAGJ,GAFAiS,EAAOhC,GAAMmC,IACbpS,EAAMgS,GAAUC,EAAMC,GAErB,MAAMlS,EAEP,OAUA,WACC,IAEIsS,EACArO,EAHA2M,EAAOvL,UAAW,GAClB8M,EAAMF,EAAKE,IAAM,SAASvB,EAG9B,IAAM3M,EAAI,EAAGA,EAAIoB,UAAUnB,OAAQD,IAClCkO,GAAO,UAAYI,mBAAoBlN,UAAWpB,IAInD,OAFAqO,EAAMnO,GAAS8N,EAAKvB,QAAS,UAAWyB,GACxCG,EAAMnO,GAASmO,EAAK,WAAY1B,KCtC9B4B,GCbUzQ,GACCH,IDWGG,EAOLyQ,GAAwB,UALvB3Q,IAUd,IAAAC,GAAiB0Q,UEiFjB,WACC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjP,EACAwM,EACAvM,EASJ,IANAwO,EAAUpN,UAAW,GACrBqN,EAASrN,UAAW,GAGpBsN,GADAG,EAAQzN,UAAW,GADnBwN,GAHAD,EAAQvN,UAAW,IAGLnB,UAECA,OACf8O,EAAMN,EACAzO,EAAI,EAAGA,EAAI4O,EAAO5O,IAAM,CAI7B,GAHAgP,EAAIL,EAAO3O,GACXuM,EAAInL,UAAWpB,EAAE,GAEH,WADd8O,EAAOD,EAAO7O,EAAE0O,IAEVnC,EAAI,EACRA,EAAI,EACOA,GAAKyC,IAChBzC,EAAIyC,EAAI,QAEH,GAAc,SAATF,EACNvC,EAAI,GACRA,GAAKyC,GACI,GAEG,KADXzC,GAAKyC,KAEJzC,GAAKyC,GAGIzC,GAAKyC,IAChBzC,GAAKyC,IACKA,IACTzC,GAAKyC,QAGD,GAAKzC,EAAI,GAAKA,GAAKyC,EACzB,MAAM,IAAIC,WAAYC,GAAQ,+FAAgGlP,EAAGuM,KAElIxM,EAAIyO,EAASxO,IAGJ,GAAgB,IAAXyO,EACbM,GAAOxC,EAAIxM,EAEXgP,GAAOxC,EAAIxM,EAGb,OAAOgP"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 4d9b415..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).sub2ind=r()}(this,(function(){"use strict";function t(t){var r=t.default;if("function"==typeof r){var e=function(){return r.apply(this,arguments)};e.prototype=r.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(t).forEach((function(r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})})),e}var r="function"==typeof Object.defineProperty?Object.defineProperty:null;var e=function(){try{return r({},"x",{}),!0}catch(t){return!1}},n=Object.defineProperty,o=Object.prototype,i=o.toString,u=o.__defineGetter__,a=o.__defineSetter__,f=o.__lookupGetter__,c=o.__lookupSetter__;var s=function(t,r,e){var n,s,l,h;if("object"!=typeof t||null===t||"[object Array]"===i.call(t))throw new TypeError("invalid argument. First argument must be an object. Value: `"+t+"`.");if("object"!=typeof e||null===e||"[object Array]"===i.call(e))throw new TypeError("invalid argument. Property descriptor must be an object. Value: `"+e+"`.");if((s="value"in e)&&(f.call(t,r)||c.call(t,r)?(n=t.__proto__,t.__proto__=o,delete t[r],t[r]=e.value,t.__proto__=n):t[r]=e.value),l="get"in e,h="set"in e,s&&(l||h))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return l&&u&&u.call(t,r,e.get),h&&a&&a.call(t,r,e.set),t},l=n,h=s,p=e()?l:h,y=p;var v=function(t,r,e){y(t,r,{configurable:!1,enumerable:!1,writable:!1,value:e})},g=v;var w=function(t){return"string"==typeof t};var d=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var b=function(){return d&&"symbol"==typeof Symbol.toStringTag},m=Object.prototype.toString,A=m;var E=function(t){return A.call(t)},_=Object.prototype.hasOwnProperty;var O=function(t,r){return null!=t&&_.call(t,r)},P="function"==typeof Symbol?Symbol.toStringTag:"",j=O,R=P,T=m;var U=E,S=function(t){var r,e,n;if(null==t)return T.call(t);e=t[R],r=j(t,R);try{t[R]=void 0}catch(r){return T.call(t)}return n=T.call(t),r?t[R]=e:delete t[R],n},I=b()?S:U,B=String.prototype.valueOf;var Y=I,x=function(t){try{return B.call(t),!0}catch(t){return!1}},C=b();var M=function(t){return"object"==typeof t&&(t instanceof String||(C?x(t):"[object String]"===Y(t)))},L=w,F=M;var D=g,N=function(t){return L(t)||F(t)},k=M;D(N,"isPrimitive",w),D(N,"isObject",k);var V=N,z=V.isPrimitive,G=/[-\/\\^$*+?.()|[\]{}]/g;var X=function(t){var r,e;if(!z(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");if("/"===t[0])for(e=t.length-1;e>=0&&"/"!==t[e];e--);return void 0===e||e<=0?t.replace(G,"\\$&"):(r=(r=t.substring(1,e)).replace(G,"\\$&"),t=t[0]+r+t.substring(e))},$=/./;var H=function(t){return"boolean"==typeof t},W=Boolean.prototype.toString;var q=I,J=function(t){try{return W.call(t),!0}catch(t){return!1}},Z=b();var K=function(t){return"object"==typeof t&&(t instanceof Boolean||(Z?J(t):"[object Boolean]"===q(t)))},Q=H,tt=K;var rt=g,et=function(t){return Q(t)||tt(t)},nt=K;rt(et,"isPrimitive",H),rt(et,"isObject",nt);var ot=et;var it=function(){return new Function("return this;")()},ut="object"==typeof self?self:null,at="object"==typeof window?window:null,ft="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},ct="object"==typeof ft?ft:null;module.exports=ct;var st=ot.isPrimitive,lt=it,ht=ut,pt=at,yt=t(Object.freeze({__proto__:null}));var vt=function(t){if(arguments.length){if(!st(t))throw new TypeError("invalid argument. Must provide a boolean primitive. Value: `"+t+"`.");if(t)return lt()}if(ht)return ht;if(pt)return pt;if(yt)return yt;throw new Error("unexpected error. Unable to resolve global object.")},gt=vt(),wt=gt.document&>.document.childNodes,dt=Int8Array,bt=$,mt=wt,At=dt;var Et=function(){return"function"==typeof bt||"object"==typeof At||"function"==typeof mt};var _t=function(){return/^\s*function\s*([^(]*)/i},Ot=_t;g(Ot,"REGEXP",_t());var Pt=Ot,jt=I;var Rt=Array.isArray?Array.isArray:function(t){return"[object Array]"===jt(t)},Tt=Rt;var Ut=function(t){return null!==t&&"object"==typeof t};g(Ut,"isObjectLikeArray",function(t){if("function"!=typeof t)throw new TypeError("invalid argument. Must provide a function. Value: `"+t+"`.");return function(r){var e,n;if(!Tt(r))return!1;if(0===(e=r.length))return!1;for(n=0;ndr&&br(t)},Ar=hr.isPrimitive,Er=mr;var _r=function(t){return Ar(t)&&Er(t)},Or=hr.isObject,Pr=mr;var jr=function(t){return Or(t)&&Pr(t.valueOf())},Rr=_r,Tr=jr;var Ur=g,Sr=function(t){return Rr(t)||Tr(t)},Ir=jr;Ur(Sr,"isPrimitive",_r),Ur(Sr,"isObject",Ir);var Br=Sr,Yr=Br.isPrimitive;var xr=function(t){return Yr(t)&&t>=0},Cr=Br.isObject;var Mr=function(t){return Cr(t)&&t.valueOf()>=0},Lr=xr,Fr=Mr;var Dr=g,Nr=function(t){return Lr(t)||Fr(t)},kr=Mr;Dr(Nr,"isPrimitive",xr),Dr(Nr,"isObject",kr);var Vr=Nr,zr=Object.getPrototypeOf;var Gr=function(t){return t.__proto__},Xr=I,$r=Gr;var Hr=function(t){var r=$r(t);return r||null===r?r:"[object Function]"===Xr(t.constructor)?t.constructor.prototype:t instanceof Object?Object.prototype:null},Wr=zr,qr=Hr,Jr=zt(Object.getPrototypeOf)?Wr:qr;var Zr=function(t){return null==t?null:(t=Object(t),Jr(t))},Kr=Zr,Qr=I;var te=function(t){if("object"!=typeof t||null===t)return!1;if(t instanceof Error)return!0;for(;t;){if("[object Error]"===Qr(t))return!0;t=Kr(t)}return!1};var re=function(){return/^\/((?:\\\/|[^\/])+)\/([imgy]*)$/},ee=re;g(ee,"REGEXP",re());var ne=V.isPrimitive,oe=ee;var ie=function(t){if(!ne(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");return(t=oe().exec(t))?new RegExp(t[1],t[2]):null};var ue=function(t){return t!=t},ae=hr.isPrimitive,fe=ue;var ce=function(t){return ae(t)&&fe(t)},se=hr.isObject,le=ue;var he=function(t){return se(t)&&le(t.valueOf())},pe=ce,ye=he;var ve=g,ge=function(t){return pe(t)||ye(t)},we=he;ve(ge,"isPrimitive",ce),ve(ge,"isObject",we);var de=ge,be=gr;var me=de,Ae=function(t){return"object"==typeof t&&null!==t&&"number"==typeof t.length&&be(t.length)&&t.length>=0&&t.length<=9007199254740991},Ee=V.isPrimitive,_e=Br.isPrimitive;var Oe=function(t,r,e){var n,o;if(!Ae(t)&&!Ee(t))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+t+"`.");if(0===(n=t.length))return-1;if(3===arguments.length){if(!_e(e))throw new TypeError("invalid argument. `fromIndex` must be an integer. Value: `"+e+"`.");if(e>=0){if(e>=n)return-1;o=e}else(o=n+e)<0&&(o=0)}else o=0;if(me(r)){for(;o=0&&r=0&&t.length<=4294967295&&Ge(t,"callee")&&!Xe(t,"callee")},qe=We,Je=je,Ze=Array.prototype.slice;var Ke=function(t){return qe(t)?Je(Ze.call(t)):Je(t)};var Qe=ze((function(){}),"prototype"),tn=!ze({toString:null},"toString");var rn,en=function(t){return t.constructor&&t.constructor.prototype===t},nn="undefined"==typeof window?void 0:window,on=O,un=Pe,an=kt,fn=en,cn=["console","external","frame","frameElement","frames","innerHeight","innerWidth","outerHeight","outerWidth","pageXOffset","pageYOffset","parent","scrollLeft","scrollTop","scrollX","scrollY","self","webkitIndexedDB","webkitStorageInfo","window"],sn=nn;rn=function(){var t;if("undefined"===an(sn))return!1;for(t in sn)try{-1===un(cn,t)&&on(sn,t)&&null!==sn[t]&&"object"===an(sn[t])&&fn(sn[t])}catch(t){return!0}return!1}();var ln="undefined"!=typeof window,hn=rn,pn=en,yn=ln;var vn=St,gn=O,wn=We,dn=Qe,bn=tn,mn=function(t){if(!1===yn&&!hn)return pn(t);try{return pn(t)}catch(t){return!1}},An=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"];var En=je,_n=Ke,On=function(t){var r,e,n,o,i,u,a;if(o=[],wn(t)){for(a=0;a0&&!gn(t,"0"))for(a=0;a>18&63]+xn[o>>12&63]+xn[o>>6&63]+xn[63&o]);return i.join("")}function Nn(t){var r;Ln||Fn();for(var e=t.length,n=e%3,o="",i=[],u=16383,a=0,f=e-n;af?f:a+u));return 1===n?(r=t[e-1],o+=xn[r>>2],o+=xn[r<<4&63],o+="=="):2===n&&(r=(t[e-2]<<8)+t[e-1],o+=xn[r>>10],o+=xn[r>>4&63],o+=xn[r<<2&63],o+="="),i.push(o),i.join("")}function kn(t,r,e,n,o){var i,u,a=8*o-n-1,f=(1<>1,s=-7,l=e?o-1:0,h=e?-1:1,p=t[r+l];for(l+=h,i=p&(1<<-s)-1,p>>=-s,s+=a;s>0;i=256*i+t[r+l],l+=h,s-=8);for(u=i&(1<<-s)-1,i>>=-s,s+=n;s>0;u=256*u+t[r+l],l+=h,s-=8);if(0===i)i=1-c;else{if(i===f)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),i-=c}return(p?-1:1)*u*Math.pow(2,i-n)}function Vn(t,r,e,n,o,i){var u,a,f,c=8*i-o-1,s=(1<>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,y=n?1:-1,v=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,u=s):(u=Math.floor(Math.log(r)/Math.LN2),r*(f=Math.pow(2,-u))<1&&(u--,f*=2),(r+=u+l>=1?h/f:h*Math.pow(2,1-l))*f>=2&&(u++,f/=2),u+l>=s?(a=0,u=s):u+l>=1?(a=(r*f-1)*Math.pow(2,o),u+=l):(a=r*Math.pow(2,l-1)*Math.pow(2,o),u=0));o>=8;t[e+p]=255&a,p+=y,a/=256,o-=8);for(u=u<0;t[e+p]=255&u,p+=y,u/=256,c-=8);t[e+p-y]|=128*v}var zn={}.toString,Gn=Array.isArray||function(t){return"[object Array]"==zn.call(t)};Wn.TYPED_ARRAY_SUPPORT=void 0===ft.TYPED_ARRAY_SUPPORT||ft.TYPED_ARRAY_SUPPORT;var Xn=$n();function $n(){return Wn.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Hn(t,r){if($n()=$n())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+$n().toString(16)+" bytes");return 0|t}function to(t){return!(null==t||!t._isBuffer)}function ro(t,r){if(to(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return Uo(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return So(t).length;default:if(n)return Uo(t).length;r=(""+r).toLowerCase(),n=!0}}function eo(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return wo(this,r,e);case"utf8":case"utf-8":return po(this,r,e);case"ascii":return vo(this,r,e);case"latin1":case"binary":return go(this,r,e);case"base64":return ho(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return bo(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function no(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function oo(t,r,e,n,o){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0){if(!o)return-1;e=0}if("string"==typeof r&&(r=Wn.from(r,n)),to(r))return 0===r.length?-1:io(t,r,e,n,o);if("number"==typeof r)return r&=255,Wn.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):io(t,[r],e,n,o);throw new TypeError("val must be string, number or Buffer")}function io(t,r,e,n,o){var i,u=1,a=t.length,f=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,a/=2,f/=2,e/=2}function c(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(o){var s=-1;for(i=e;ia&&(e=a-f),i=e;i>=0;i--){for(var l=!0,h=0;ho&&(n=o):n=o;var i=r.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var u=0;u>8,o=e%256,i.push(o),i.push(n);return i}(r,t.length-e),t,e,n)}function ho(t,r,e){return 0===r&&e===t.length?Nn(t):Nn(t.slice(r,e))}function po(t,r,e){e=Math.min(t.length,e);for(var n=[],o=r;o239?4:c>223?3:c>191?2:1;if(o+l<=e)switch(l){case 1:c<128&&(s=c);break;case 2:128==(192&(i=t[o+1]))&&(f=(31&c)<<6|63&i)>127&&(s=f);break;case 3:i=t[o+1],u=t[o+2],128==(192&i)&&128==(192&u)&&(f=(15&c)<<12|(63&i)<<6|63&u)>2047&&(f<55296||f>57343)&&(s=f);break;case 4:i=t[o+1],u=t[o+2],a=t[o+3],128==(192&i)&&128==(192&u)&&128==(192&a)&&(f=(15&c)<<18|(63&i)<<12|(63&u)<<6|63&a)>65535&&f<1114112&&(s=f)}null===s?(s=65533,l=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=l}return function(t){var r=t.length;if(r<=yo)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),""},Wn.prototype.compare=function(t,r,e,n,o){if(!to(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),r<0||e>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&r>=e)return 0;if(n>=o)return-1;if(r>=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),a=Math.min(i,u),f=this.slice(n,o),c=t.slice(r,e),s=0;so)&&(e=o),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return uo(this,t,r,e);case"utf8":case"utf-8":return ao(this,t,r,e);case"ascii":return fo(this,t,r,e);case"latin1":case"binary":return co(this,t,r,e);case"base64":return so(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return lo(this,t,r,e);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},Wn.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var yo=4096;function vo(t,r,e){var n="";e=Math.min(t.length,e);for(var o=r;on)&&(e=n);for(var o="",i=r;ie)throw new RangeError("Trying to access beyond buffer length")}function Ao(t,r,e,n,o,i){if(!to(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>o||rt.length)throw new RangeError("Index out of range")}function Eo(t,r,e,n){r<0&&(r=65535+r+1);for(var o=0,i=Math.min(t.length-e,2);o>>8*(n?o:1-o)}function _o(t,r,e,n){r<0&&(r=4294967295+r+1);for(var o=0,i=Math.min(t.length-e,4);o>>8*(n?o:3-o)&255}function Oo(t,r,e,n,o,i){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function Po(t,r,e,n,o){return o||Oo(t,0,e,4),Vn(t,r,e,n,23,4),e+4}function jo(t,r,e,n,o){return o||Oo(t,0,e,8),Vn(t,r,e,n,52,8),e+8}Wn.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(o*=256);)n+=this[t+--r]*o;return n},Wn.prototype.readUInt8=function(t,r){return r||mo(t,1,this.length),this[t]},Wn.prototype.readUInt16LE=function(t,r){return r||mo(t,2,this.length),this[t]|this[t+1]<<8},Wn.prototype.readUInt16BE=function(t,r){return r||mo(t,2,this.length),this[t]<<8|this[t+1]},Wn.prototype.readUInt32LE=function(t,r){return r||mo(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Wn.prototype.readUInt32BE=function(t,r){return r||mo(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Wn.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||mo(t,r,this.length);for(var n=this[t],o=1,i=0;++i=(o*=128)&&(n-=Math.pow(2,8*r)),n},Wn.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||mo(t,r,this.length);for(var n=r,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*r)),i},Wn.prototype.readInt8=function(t,r){return r||mo(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Wn.prototype.readInt16LE=function(t,r){r||mo(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},Wn.prototype.readInt16BE=function(t,r){r||mo(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},Wn.prototype.readInt32LE=function(t,r){return r||mo(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Wn.prototype.readInt32BE=function(t,r){return r||mo(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Wn.prototype.readFloatLE=function(t,r){return r||mo(t,4,this.length),kn(this,t,!0,23,4)},Wn.prototype.readFloatBE=function(t,r){return r||mo(t,4,this.length),kn(this,t,!1,23,4)},Wn.prototype.readDoubleLE=function(t,r){return r||mo(t,8,this.length),kn(this,t,!0,52,8)},Wn.prototype.readDoubleBE=function(t,r){return r||mo(t,8,this.length),kn(this,t,!1,52,8)},Wn.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||Ao(this,t,r,e,Math.pow(2,8*e)-1,0);var o=1,i=0;for(this[r]=255&t;++i=0&&(i*=256);)this[r+o]=t/i&255;return r+e},Wn.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,1,255,0),Wn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},Wn.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,65535,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):Eo(this,t,r,!0),r+2},Wn.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,65535,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):Eo(this,t,r,!1),r+2},Wn.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,4294967295,0),Wn.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):_o(this,t,r,!0),r+4},Wn.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,4294967295,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):_o(this,t,r,!1),r+4},Wn.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Ao(this,t,r,e,o-1,-o)}var i=0,u=1,a=0;for(this[r]=255&t;++i>0)-a&255;return r+e},Wn.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Ao(this,t,r,e,o-1,-o)}var i=e-1,u=1,a=0;for(this[r+i]=255&t;--i>=0&&(u*=256);)t<0&&0===a&&0!==this[r+i+1]&&(a=1),this[r+i]=(t/u>>0)-a&255;return r+e},Wn.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,1,127,-128),Wn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},Wn.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,32767,-32768),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):Eo(this,t,r,!0),r+2},Wn.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,32767,-32768),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):Eo(this,t,r,!1),r+2},Wn.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,2147483647,-2147483648),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):_o(this,t,r,!0),r+4},Wn.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):_o(this,t,r,!1),r+4},Wn.prototype.writeFloatLE=function(t,r,e){return Po(this,t,r,!0,e)},Wn.prototype.writeFloatBE=function(t,r,e){return Po(this,t,r,!1,e)},Wn.prototype.writeDoubleLE=function(t,r,e){return jo(this,t,r,!0,e)},Wn.prototype.writeDoubleBE=function(t,r,e){return jo(this,t,r,!1,e)},Wn.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--o)t[o+r]=this[o+e];else if(i<1e3||!Wn.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(i=r;i55295&&e<57344){if(!o){if(e>56319){(r-=3)>-1&&i.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&i.push(239,191,189);continue}o=e;continue}if(e<56320){(r-=3)>-1&&i.push(239,191,189),o=e;continue}e=65536+(o-55296<<10|e-56320)}else o&&(r-=3)>-1&&i.push(239,191,189);if(o=null,e<128){if((r-=1)<0)break;i.push(e)}else if(e<2048){if((r-=2)<0)break;i.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;i.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;i.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return i}function So(t){return function(t){var r,e,n,o,i,u;Ln||Fn();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[a-2]?2:"="===t[a-1]?1:0,u=new Mn(3*a/4-i),n=i>0?a-4:a;var f=0;for(r=0,e=0;r>16&255,u[f++]=o>>8&255,u[f++]=255&o;return 2===i?(o=Cn[t.charCodeAt(r)]<<2|Cn[t.charCodeAt(r+1)]>>4,u[f++]=255&o):1===i&&(o=Cn[t.charCodeAt(r)]<<10|Cn[t.charCodeAt(r+1)]<<4|Cn[t.charCodeAt(r+2)]>>2,u[f++]=o>>8&255,u[f++]=255&o),u}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Ro,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Io(t,r,e,n){for(var o=0;o=r.length||o>=t.length);++o)r[o+e]=t[o];return o}function Bo(t){return null!=t&&(!!t._isBuffer||Yo(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&Yo(t.slice(0,0))}(t))}function Yo(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var xo=Object.freeze({__proto__:null,Buffer:Wn,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),Wn.alloc(+t)},isBuffer:Bo,kMaxLength:Xn}),Co=Wn;module.exports=Co;var Mo=Bt,Lo=t(Object.freeze({__proto__:null}));var Fo=function(){var t,r;if("function"!=typeof Lo)return!1;try{r="function"==typeof Lo.from?Lo.from([1,2,3,4]):new Lo([1,2,3,4]),t=Mo(r)&&1===r[0]&&2===r[1]&&3===r[2]&&4===r[3]}catch(r){t=!1}return t},Do=Fo;var No=t(xo).Buffer,ko=function(){throw new Error("not implemented")},Vo=Do()?No:ko,zo=zt(Vo.from),Go=Bt,Xo=Vo;var $o=function(t){if(!Go(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return Xo.from(t)},Ho=Bt,Wo=Vo;var qo=function(t){if(!Ho(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return new Wo(t)},Jo=zo?$o:qo,Zo=I,Ko="function"==typeof Int8Array;var Qo="function"==typeof Int8Array?Int8Array:null,ti=function(t){return Ko&&t instanceof Int8Array||"[object Int8Array]"===Zo(t)},ri=Qo;var ei=function(){var t,r;if("function"!=typeof ri)return!1;try{r=new ri([1,3.14,-3.14,128]),t=ti(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-128===r[3]}catch(r){t=!1}return t};var ni="function"==typeof Int8Array?Int8Array:void 0,oi=function(){throw new Error("not implemented")},ii=ei()?ni:oi,ui=I,ai="function"==typeof Uint8Array;var fi="function"==typeof Uint8Array?Uint8Array:null,ci=function(t){return ai&&t instanceof Uint8Array||"[object Uint8Array]"===ui(t)},si=fi;var li=function(){var t,r;if("function"!=typeof si)return!1;try{r=new si(r=[1,3.14,-3.14,256,257]),t=ci(r)&&1===r[0]&&3===r[1]&&253===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var hi="function"==typeof Uint8Array?Uint8Array:void 0,pi=function(){throw new Error("not implemented")},yi=li()?hi:pi,vi=I,gi="function"==typeof Uint8ClampedArray;var wi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:null,di=function(t){return gi&&t instanceof Uint8ClampedArray||"[object Uint8ClampedArray]"===vi(t)},bi=wi;var mi=function(){var t,r;if("function"!=typeof bi)return!1;try{r=new bi([-1,0,1,3.14,4.99,255,256]),t=di(r)&&0===r[0]&&0===r[1]&&1===r[2]&&3===r[3]&&5===r[4]&&255===r[5]&&255===r[6]}catch(r){t=!1}return t};var Ai="function"==typeof Uint8ClampedArray?Uint8ClampedArray:void 0,Ei=function(){throw new Error("not implemented")},_i=mi()?Ai:Ei,Oi=I,Pi="function"==typeof Int16Array;var ji="function"==typeof Int16Array?Int16Array:null,Ri=function(t){return Pi&&t instanceof Int16Array||"[object Int16Array]"===Oi(t)},Ti=ji;var Ui=function(){var t,r;if("function"!=typeof Ti)return!1;try{r=new Ti([1,3.14,-3.14,32768]),t=Ri(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-32768===r[3]}catch(r){t=!1}return t};var Si="function"==typeof Int16Array?Int16Array:void 0,Ii=function(){throw new Error("not implemented")},Bi=Ui()?Si:Ii,Yi=I,xi="function"==typeof Uint16Array;var Ci="function"==typeof Uint16Array?Uint16Array:null,Mi=function(t){return xi&&t instanceof Uint16Array||"[object Uint16Array]"===Yi(t)},Li=Ci;var Fi=function(){var t,r;if("function"!=typeof Li)return!1;try{r=new Li(r=[1,3.14,-3.14,65536,65537]),t=Mi(r)&&1===r[0]&&3===r[1]&&65533===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var Di="function"==typeof Uint16Array?Uint16Array:void 0,Ni=function(){throw new Error("not implemented")},ki=Fi()?Di:Ni,Vi=I,zi="function"==typeof Int32Array;var Gi="function"==typeof Int32Array?Int32Array:null,Xi=function(t){return zi&&t instanceof Int32Array||"[object Int32Array]"===Vi(t)},$i=Gi;var Hi=function(){var t,r;if("function"!=typeof $i)return!1;try{r=new $i([1,3.14,-3.14,2147483648]),t=Xi(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-2147483648===r[3]}catch(r){t=!1}return t};var Wi="function"==typeof Int32Array?Int32Array:void 0,qi=function(){throw new Error("not implemented")},Ji=Hi()?Wi:qi,Zi=I,Ki="function"==typeof Uint32Array;var Qi="function"==typeof Uint32Array?Uint32Array:null,tu=function(t){return Ki&&t instanceof Uint32Array||"[object Uint32Array]"===Zi(t)},ru=Qi;var eu=function(){var t,r;if("function"!=typeof ru)return!1;try{r=new ru(r=[1,3.14,-3.14,4294967296,4294967297]),t=tu(r)&&1===r[0]&&3===r[1]&&4294967293===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var nu="function"==typeof Uint32Array?Uint32Array:void 0,ou=function(){throw new Error("not implemented")},iu=eu()?nu:ou,uu=I,au="function"==typeof Float32Array;var fu="function"==typeof Float32Array?Float32Array:null,cu=function(t){return au&&t instanceof Float32Array||"[object Float32Array]"===uu(t)},su=pr,lu=fu;var hu=function(){var t,r;if("function"!=typeof lu)return!1;try{r=new lu([1,3.14,-3.14,5e40]),t=cu(r)&&1===r[0]&&3.140000104904175===r[1]&&-3.140000104904175===r[2]&&r[3]===su}catch(r){t=!1}return t};var pu="function"==typeof Float32Array?Float32Array:void 0,yu=function(){throw new Error("not implemented")},vu=hu()?pu:yu,gu=I,wu="function"==typeof Float64Array;var du="function"==typeof Float64Array?Float64Array:null,bu=function(t){return wu&&t instanceof Float64Array||"[object Float64Array]"===gu(t)},mu=du;var Au=function(){var t,r;if("function"!=typeof mu)return!1;try{r=new mu([1,3.14,-3.14,NaN]),t=bu(r)&&1===r[0]&&3.14===r[1]&&-3.14===r[2]&&r[3]!=r[3]}catch(r){t=!1}return t};var Eu,_u="function"==typeof Float64Array?Float64Array:void 0,Ou=function(){throw new Error("not implemented")};Eu=Au()?_u:Ou;var Pu=ii,ju=yi,Ru=_i,Tu=Bi,Uu=ki,Su=Ji,Iu=iu,Bu=vu,Yu=Eu;function xu(t){return new Pu(t)}function Cu(t){return new ju(t)}function Mu(t){return new Ru(t)}function Lu(t){return new Tu(t)}function Fu(t){return new Uu(t)}function Du(t){return new Su(t)}function Nu(t){return new Iu(t)}function ku(t){return new Bu(t)}function Vu(t){return new Yu(t)}var zu=O,Gu=Rt,Xu=Bt,$u=te,Hu=kt,Wu=ie,qu=Pe,Ju=Pn,Zu=Un,Ku=Yn,Qu=Zr,ta=p,ra=Jo,ea={int8array:xu,uint8array:Cu,uint8clampedarray:Mu,int16array:Lu,uint16array:Fu,int32array:Du,uint32array:Nu,float32array:ku,float64array:Vu};function na(t,r,e,n,o){var i,u,a,f,c,s,l,h,p,y;if(o-=1,"object"!=typeof t||null===t)return t;if(Xu(t))return ra(t);if($u(t))return function(t){var r,e,n,o,i,u,a=[],f=[];for(i=new t.constructor(t.message),a.push(t),f.push(i),t.stack&&(i.stack=t.stack),t.code&&(i.code=t.code),t.errno&&(i.errno=t.errno),t.syscall&&(i.syscall=t.syscall),r=Ju(t),u=0;u0)for(i=a,y=0;y1){if(!ia(r))throw new TypeError("invalid argument. `level` must be a nonnegative integer. Value: `"+r+"`.");if(0===r)return t}else r=ua;return e=oa(t)?new Array(t.length):{},aa(t,e,[t],[e],r)},ca=fa,sa=Rt;var la=function(t){return"object"==typeof t&&null!==t&&!sa(t)},ha=zt,pa=Zr,ya=O,va=I,ga=Object.prototype;var wa=function(t){var r;return!!la(t)&&(!(r=pa(t))||!ya(t,"constructor")&&ya(r,"constructor")&&ha(r.constructor)&&"[object Function]"===va(r.constructor)&&ya(r,"isPrototypeOf")&&ha(r.isPrototypeOf)&&(r===ga||function(t){var r;for(r in t)if(!ya(t,r))return!1;return!0}(t)))},da=wa,ba=O,ma=V.isPrimitive;var Aa={url:"https://stdlib.io/docs/api/latest/error-decoder.html",message:"Minified stdlib error code: {{code}}. Visit {{url}} for the full message."},Ea=Kt,_a=ca,Oa=function(t,r){return da(r)?ba(r,"url")&&(t.url=r.url,!ma(t.url))?new TypeError("invalid option. `url` option must be a string primitive. Option: `"+t.url+"`."):ba(r,"message")&&(t.message=r.message,!ma(t.message))?new TypeError("invalid option. `message` option must be a string primitive. Option: `"+t.message+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.")},Pa=Aa;var ja=function(t){var r,e;if(r=_a(Pa),e=Oa(r,t))throw e;return function(){var t,e,n=arguments[0],o=r.url+"?code="+n;for(e=1;e=f&&(s=f-1);else if("wrap"===u)s<0?(s+=f)<0&&0!==(s%=f)&&(s+=f):s>=f&&(s-=f)>=f&&(s%=f);else if(s<0||s>=f)throw new RangeError(Ta("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",l,s));(c=t[l])<0&&0===r?a-=s*c:a+=s*c}return a}})); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index e1abfe1..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/utils-define-property/lib/define_property.js","../node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js","../node_modules/@stdlib/utils-define-property/lib/builtin.js","../node_modules/@stdlib/utils-define-property/lib/polyfill.js","../node_modules/@stdlib/utils-define-property/lib/index.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/primitive.js","../node_modules/@stdlib/assert-has-symbol-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostring.js","../node_modules/@stdlib/utils-native-class/lib/native_class.js","../node_modules/@stdlib/assert-has-own-property/lib/main.js","../node_modules/@stdlib/assert-has-own-property/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostringtag.js","../node_modules/@stdlib/utils-native-class/lib/polyfill.js","../node_modules/@stdlib/utils-native-class/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/try2valueof.js","../node_modules/@stdlib/assert-is-string/lib/valueof.js","../node_modules/@stdlib/assert-is-string/lib/object.js","../node_modules/@stdlib/assert-is-string/lib/main.js","../node_modules/@stdlib/assert-is-string/lib/index.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/main.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/re.js","../node_modules/@stdlib/assert-is-boolean/lib/primitive.js","../node_modules/@stdlib/assert-is-boolean/lib/try2serialize.js","../node_modules/@stdlib/assert-is-boolean/lib/tostring.js","../node_modules/@stdlib/assert-is-boolean/lib/object.js","../node_modules/@stdlib/assert-is-boolean/lib/main.js","../node_modules/@stdlib/assert-is-boolean/lib/index.js","../node_modules/@stdlib/utils-global/lib/codegen.js","../node_modules/@stdlib/utils-global/lib/self.js","../node_modules/@stdlib/utils-global/lib/window.js","../node_modules/@stdlib/utils-global/lib/global.js","../node_modules/@stdlib/utils-global/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/nodelist.js","../node_modules/@stdlib/utils-global/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/typedarray.js","../node_modules/@stdlib/utils-type-of/lib/check.js","../node_modules/@stdlib/regexp-function-name/lib/main.js","../node_modules/@stdlib/regexp-function-name/lib/index.js","../node_modules/@stdlib/regexp-function-name/lib/regexp.js","../node_modules/@stdlib/assert-is-array/lib/main.js","../node_modules/@stdlib/assert-is-array/lib/index.js","../node_modules/@stdlib/assert-tools-array-function/lib/arrayfcn.js","../node_modules/@stdlib/assert-is-object-like/lib/main.js","../node_modules/@stdlib/assert-is-object-like/lib/index.js","../node_modules/@stdlib/assert-is-buffer/lib/main.js","../node_modules/@stdlib/assert-is-buffer/lib/index.js","../node_modules/@stdlib/utils-constructor-name/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/typeof.js","../node_modules/@stdlib/utils-constructor-name/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/polyfill.js","../node_modules/@stdlib/utils-type-of/lib/index.js","../node_modules/@stdlib/assert-is-function/lib/main.js","../node_modules/@stdlib/assert-is-function/lib/index.js","../node_modules/@stdlib/assert-is-regexp/lib/try2exec.js","../node_modules/@stdlib/assert-is-regexp/lib/exec.js","../node_modules/@stdlib/assert-is-regexp/lib/main.js","../node_modules/@stdlib/string-replace/lib/replace.js","../node_modules/@stdlib/string-replace/lib/index.js","../node_modules/@stdlib/assert-is-number/lib/primitive.js","../node_modules/@stdlib/number-ctor/lib/index.js","../node_modules/@stdlib/number-ctor/lib/number.js","../node_modules/@stdlib/assert-is-number/lib/try2serialize.js","../node_modules/@stdlib/assert-is-number/lib/tostring.js","../node_modules/@stdlib/assert-is-number/lib/object.js","../node_modules/@stdlib/assert-is-number/lib/main.js","../node_modules/@stdlib/assert-is-number/lib/index.js","../node_modules/@stdlib/constants-float64-pinf/lib/index.js","../node_modules/@stdlib/constants-float64-ninf/lib/index.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/is_integer.js","../node_modules/@stdlib/math-base-special-floor/lib/main.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-integer/lib/integer.js","../node_modules/@stdlib/assert-is-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-integer/lib/object.js","../node_modules/@stdlib/assert-is-integer/lib/main.js","../node_modules/@stdlib/assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/object.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/main.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/index.js","../node_modules/@stdlib/utils-get-prototype-of/lib/native.js","../node_modules/@stdlib/utils-get-prototype-of/lib/proto.js","../node_modules/@stdlib/utils-get-prototype-of/lib/polyfill.js","../node_modules/@stdlib/utils-get-prototype-of/lib/detect.js","../node_modules/@stdlib/utils-get-prototype-of/lib/get_prototype_of.js","../node_modules/@stdlib/utils-get-prototype-of/lib/index.js","../node_modules/@stdlib/assert-is-error/lib/main.js","../node_modules/@stdlib/assert-is-error/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/main.js","../node_modules/@stdlib/regexp-regexp/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/regexp.js","../node_modules/@stdlib/utils-regexp-from-string/lib/from_string.js","../node_modules/@stdlib/utils-regexp-from-string/lib/index.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/primitive.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-nan/lib/object.js","../node_modules/@stdlib/assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-collection/lib/main.js","../node_modules/@stdlib/utils-index-of/lib/index_of.js","../node_modules/@stdlib/constants-array-max-typed-array-length/lib/index.js","../node_modules/@stdlib/utils-index-of/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin.js","../node_modules/@stdlib/utils-keys/lib/has_arguments_bug.js","../node_modules/@stdlib/utils-keys/lib/has_builtin.js","../node_modules/@stdlib/assert-is-arguments/lib/main.js","../node_modules/@stdlib/assert-is-arguments/lib/detect.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/has_string_enumerability_bug.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/native.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/main.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/index.js","../node_modules/@stdlib/assert-is-arguments/lib/polyfill.js","../node_modules/@stdlib/assert-is-arguments/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin_wrapper.js","../node_modules/@stdlib/utils-noop/lib/noop.js","../node_modules/@stdlib/utils-keys/lib/has_enumerable_prototype_bug.js","../node_modules/@stdlib/utils-keys/lib/has_non_enumerable_properties_bug.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype.js","../node_modules/@stdlib/utils-keys/lib/has_automation_equality_bug.js","../node_modules/@stdlib/utils-keys/lib/window.js","../node_modules/@stdlib/utils-keys/lib/has_window.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype_wrapper.js","../node_modules/@stdlib/utils-keys/lib/polyfill.js","../node_modules/@stdlib/utils-keys/lib/main.js","../node_modules/@stdlib/utils-keys/lib/index.js","../node_modules/@stdlib/utils-property-names/lib/has_builtin.js","../node_modules/@stdlib/utils-property-names/lib/builtin.js","../node_modules/@stdlib/utils-property-names/lib/polyfill.js","../node_modules/@stdlib/utils-property-names/lib/index.js","../node_modules/@stdlib/utils-property-descriptor/lib/has_builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/polyfill.js","../node_modules/@stdlib/utils-property-descriptor/lib/index.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/buffer.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/main.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/polyfill.js","../node_modules/@stdlib/buffer-ctor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/buffer.js","../node_modules/@stdlib/buffer-from-buffer/lib/has_from.js","../node_modules/@stdlib/buffer-from-buffer/lib/main.js","../node_modules/@stdlib/buffer-from-buffer/lib/polyfill.js","../node_modules/@stdlib/buffer-from-buffer/lib/index.js","../node_modules/@stdlib/assert-is-int8array/lib/main.js","../node_modules/@stdlib/assert-has-int8array-support/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/main.js","../node_modules/@stdlib/constants-int8-min/lib/index.js","../node_modules/@stdlib/array-int8/lib/polyfill.js","../node_modules/@stdlib/array-int8/lib/index.js","../node_modules/@stdlib/array-int8/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8array/lib/main.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/main.js","../node_modules/@stdlib/array-uint8/lib/polyfill.js","../node_modules/@stdlib/array-uint8/lib/index.js","../node_modules/@stdlib/array-uint8/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8clampedarray/lib/main.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/main.js","../node_modules/@stdlib/array-uint8c/lib/polyfill.js","../node_modules/@stdlib/array-uint8c/lib/index.js","../node_modules/@stdlib/array-uint8c/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/index.js","../node_modules/@stdlib/assert-is-int16array/lib/main.js","../node_modules/@stdlib/assert-has-int16array-support/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/main.js","../node_modules/@stdlib/constants-int16-min/lib/index.js","../node_modules/@stdlib/array-int16/lib/polyfill.js","../node_modules/@stdlib/array-int16/lib/index.js","../node_modules/@stdlib/array-int16/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint16array/lib/main.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/main.js","../node_modules/@stdlib/array-uint16/lib/polyfill.js","../node_modules/@stdlib/array-uint16/lib/index.js","../node_modules/@stdlib/array-uint16/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/index.js","../node_modules/@stdlib/assert-is-int32array/lib/main.js","../node_modules/@stdlib/assert-has-int32array-support/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/main.js","../node_modules/@stdlib/constants-int32-min/lib/index.js","../node_modules/@stdlib/array-int32/lib/polyfill.js","../node_modules/@stdlib/array-int32/lib/index.js","../node_modules/@stdlib/array-int32/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint32array/lib/main.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/main.js","../node_modules/@stdlib/array-uint32/lib/polyfill.js","../node_modules/@stdlib/array-uint32/lib/index.js","../node_modules/@stdlib/array-uint32/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float32array/lib/main.js","../node_modules/@stdlib/assert-has-float32array-support/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/main.js","../node_modules/@stdlib/array-float32/lib/polyfill.js","../node_modules/@stdlib/array-float32/lib/index.js","../node_modules/@stdlib/array-float32/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float64array/lib/main.js","../node_modules/@stdlib/assert-has-float64array-support/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/main.js","../node_modules/@stdlib/array-float64/lib/polyfill.js","../node_modules/@stdlib/array-float64/lib/index.js","../node_modules/@stdlib/array-float64/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/index.js","../node_modules/@stdlib/utils-copy/lib/typed_arrays.js","../node_modules/@stdlib/utils-copy/lib/deep_copy.js","../node_modules/@stdlib/utils-copy/lib/copy.js","../node_modules/@stdlib/utils-copy/lib/index.js","../node_modules/@stdlib/assert-is-object/lib/main.js","../node_modules/@stdlib/assert-is-plain-object/lib/main.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/validate.js","../node_modules/@stdlib/assert-is-plain-object/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/factory.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\nvar main = ( typeof Object.defineProperty === 'function' ) ? Object.defineProperty : null;\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar defineProperty = require( './define_property.js' );\n\n\n// MAIN //\n\n/**\n* Tests for `Object.defineProperty` support.\n*\n* @private\n* @returns {boolean} boolean indicating if an environment has `Object.defineProperty` support\n*\n* @example\n* var bool = hasDefinePropertySupport();\n* // returns \n*/\nfunction hasDefinePropertySupport() {\n\t// Test basic support...\n\ttry {\n\t\tdefineProperty( {}, 'x', {} );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasDefinePropertySupport;\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// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @name defineProperty\n* @type {Function}\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nvar defineProperty = Object.defineProperty;\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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/* eslint-disable no-underscore-dangle, no-proto */\n\n'use strict';\n\n// VARIABLES //\n\nvar objectProtoype = Object.prototype;\nvar toStr = objectProtoype.toString;\nvar defineGetter = objectProtoype.__defineGetter__;\nvar defineSetter = objectProtoype.__defineSetter__;\nvar lookupGetter = objectProtoype.__lookupGetter__;\nvar lookupSetter = objectProtoype.__lookupSetter__;\n\n\n// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @param {Object} obj - object on which to define the property\n* @param {string} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nfunction defineProperty( obj, prop, descriptor ) {\n\tvar prototype;\n\tvar hasValue;\n\tvar hasGet;\n\tvar hasSet;\n\n\tif ( typeof obj !== 'object' || obj === null || toStr.call( obj ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an object. Value: `' + obj + '`.' );\n\t}\n\tif ( typeof descriptor !== 'object' || descriptor === null || toStr.call( descriptor ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. Property descriptor must be an object. Value: `' + descriptor + '`.' );\n\t}\n\thasValue = ( 'value' in descriptor );\n\tif ( hasValue ) {\n\t\tif (\n\t\t\tlookupGetter.call( obj, prop ) ||\n\t\t\tlookupSetter.call( obj, prop )\n\t\t) {\n\t\t\t// Override `__proto__` to avoid touching inherited accessors:\n\t\t\tprototype = obj.__proto__;\n\t\t\tobj.__proto__ = objectProtoype;\n\n\t\t\t// Delete property as existing getters/setters prevent assigning value to specified property:\n\t\t\tdelete obj[ prop ];\n\t\t\tobj[ prop ] = descriptor.value;\n\n\t\t\t// Restore original prototype:\n\t\t\tobj.__proto__ = prototype;\n\t\t} else {\n\t\t\tobj[ prop ] = descriptor.value;\n\t\t}\n\t}\n\thasGet = ( 'get' in descriptor );\n\thasSet = ( 'set' in descriptor );\n\n\tif ( hasValue && ( hasGet || hasSet ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.' );\n\t}\n\n\tif ( hasGet && defineGetter ) {\n\t\tdefineGetter.call( obj, prop, descriptor.get );\n\t}\n\tif ( hasSet && defineSetter ) {\n\t\tdefineSetter.call( obj, prop, descriptor.set );\n\t}\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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* Define (or modify) an object property.\n*\n* @module @stdlib/utils-define-property\n*\n* @example\n* var defineProperty = require( '@stdlib/utils-define-property' );\n*\n* var obj = {};\n* defineProperty( obj, 'foo', {\n* 'value': 'bar',\n* 'writable': false,\n* 'configurable': false,\n* 'enumerable': false\n* });\n* obj.foo = 'boop'; // => throws\n*/\n\n// MODULES //\n\nvar hasDefinePropertySupport = require( './has_define_property_support.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar defineProperty;\nif ( hasDefinePropertySupport() ) {\n\tdefineProperty = builtin;\n} else {\n\tdefineProperty = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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\nvar defineProperty = require( '@stdlib/utils-define-property' );\n\n\n// MAIN //\n\n/**\n* Defines a non-enumerable read-only property.\n*\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setNonEnumerableReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Define a non-enumerable read-only property.\n*\n* @module @stdlib/utils-define-nonenumerable-read-only-property\n*\n* @example\n* var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\n*\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\n\n// MODULES //\n\nvar setNonEnumerableReadOnly = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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// MAIN //\n\n/**\n* Tests for native `Symbol` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Symbol` support\n*\n* @example\n* var bool = hasSymbolSupport();\n* // returns \n*/\nfunction hasSymbolSupport() {\n\treturn (\n\t\ttypeof Symbol === 'function' &&\n\t\ttypeof Symbol( 'foo' ) === 'symbol'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasSymbolSupport;\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\nvar hasSymbols = require( '@stdlib/assert-has-symbol-support' );\n\n\n// VARIABLES //\n\nvar FLG = hasSymbols();\n\n\n// MAIN //\n\n/**\n* Tests for native `toStringTag` support.\n*\n* @returns {boolean} boolean indicating if an environment has `toStringTag` support\n*\n* @example\n* var bool = hasToStringTagSupport();\n* // returns \n*/\nfunction hasToStringTagSupport() {\n\treturn ( FLG && typeof Symbol.toStringTag === 'symbol' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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* Test for native `toStringTag` support.\n*\n* @module @stdlib/assert-has-tostringtag-support\n*\n* @example\n* var hasToStringTagSupport = require( '@stdlib/assert-has-tostringtag-support' );\n*\n* var bool = hasToStringTagSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasToStringTagSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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// MAIN //\n\nvar toStr = Object.prototype.toString;\n\n\n// EXPORTS //\n\nmodule.exports = toStr;\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\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification (via the internal property `[[Class]]`) of an object.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\treturn toStr.call( v );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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// FUNCTIONS //\n\nvar has = Object.prototype.hasOwnProperty;\n\n\n// MAIN //\n\n/**\n* Tests if an object has a specified property.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object has a specified property\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'bap' );\n* // returns false\n*/\nfunction hasOwnProp( value, property ) {\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\treturn has.call( value, property );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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* Test whether an object has a specified property.\n*\n* @module @stdlib/assert-has-own-property\n*\n* @example\n* var hasOwnProp = require( '@stdlib/assert-has-own-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* bool = hasOwnProp( beep, 'bop' );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasOwnProp = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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// MAIN //\n\nvar toStrTag = ( typeof Symbol === 'function' ) ? Symbol.toStringTag : '';\n\n\n// EXPORTS //\n\nmodule.exports = toStrTag;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar toStringTag = require( './tostringtag.js' );\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification of an object in environments supporting `Symbol.toStringTag`.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\tvar isOwn;\n\tvar tag;\n\tvar out;\n\n\tif ( v === null || v === void 0 ) {\n\t\treturn toStr.call( v );\n\t}\n\ttag = v[ toStringTag ];\n\tisOwn = hasOwnProp( v, toStringTag );\n\n\t// Attempt to override the `toStringTag` property. For built-ins having a `Symbol.toStringTag` property (e.g., `JSON`, `Math`, etc), the `Symbol.toStringTag` property is read-only (e.g., , so we need to wrap in a `try/catch`.\n\ttry {\n\t\tv[ toStringTag ] = void 0;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn toStr.call( v );\n\t}\n\tout = toStr.call( v );\n\n\tif ( isOwn ) {\n\t\tv[ toStringTag ] = tag;\n\t} else {\n\t\tdelete v[ toStringTag ];\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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* Return a string value indicating a specification defined classification of an object.\n*\n* @module @stdlib/utils-native-class\n*\n* @example\n* var nativeClass = require( '@stdlib/utils-native-class' );\n*\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* function Beep() {\n* return this;\n* }\n* str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\n\n// MODULES //\n\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar builtin = require( './native_class.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar nativeClass;\nif ( hasToStringTag() ) {\n\tnativeClass = polyfill;\n} else {\n\tnativeClass = builtin;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to extract a string value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a string can be extracted\n*/\nfunction test( value ) {\n\ttry {\n\t\tvalueOf.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar valueOf = String.prototype.valueOf; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2valueof.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string object\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns false\n*/\nfunction isString( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof String ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object String]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a string\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*/\nfunction isString( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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* Test if a value is a string.\n*\n* @module @stdlib/assert-is-string\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' );\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 5 );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isObject;\n*\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 'beep' );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isString = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isString, 'isPrimitive', isPrimitive );\nsetReadOnly( isString, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// VARIABLES //\n\nvar RE_CHARS = /[-\\/\\\\^$*+?.()|[\\]{}]/g; // eslint-disable-line no-useless-escape\n\n\n// MAIN //\n\n/**\n* Escapes a regular expression string.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} first argument must be a string primitive\n* @returns {string} escaped string\n*\n* @example\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\nfunction rescape( str ) {\n\tvar len;\n\tvar s;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Check if the string starts with a forward slash...\n\tif ( str[ 0 ] === '/' ) {\n\t\t// Find the last forward slash...\n\t\tlen = str.length;\n\t\tfor ( i = len-1; i >= 0; i-- ) {\n\t\t\tif ( str[ i ] === '/' ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:\n\tif ( i === void 0 || i <= 0 ) {\n\t\treturn str.replace( RE_CHARS, '\\\\$&' );\n\t}\n\t// We need to de-construct the string...\n\ts = str.substring( 1, i );\n\n\t// Only escape the characters between the `/`:\n\ts = s.replace( RE_CHARS, '\\\\$&' );\n\n\t// Reassemble:\n\tstr = str[ 0 ] + s + str.substring( i );\n\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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* Escape a regular expression string or pattern.\n*\n* @module @stdlib/utils-escape-regexp-string\n*\n* @example\n* var rescape = require( '@stdlib/utils-escape-regexp-string' );\n*\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\n\n// MODULES //\n\nvar rescape = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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\nvar RE = /./;\n\n\n// EXPORTS //\n\nmodule.exports = RE;\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* Tests if a value is a boolean primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean primitive\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns false\n*/\nfunction isBoolean( value ) {\n\treturn ( typeof value === 'boolean' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Boolean.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean object\n*\n* @example\n* var bool = isBoolean( true );\n* // returns false\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Boolean ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Boolean]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a boolean\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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* Test if a value is a boolean.\n*\n* @module @stdlib/assert-is-boolean\n*\n* @example\n* var isBoolean = require( '@stdlib/assert-is-boolean' );\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* // Use interface to check for boolean primitives...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( true ) );\n* // returns false\n*\n* @example\n* // Use interface to check for boolean objects...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isObject;\n*\n* var bool = isBoolean( true );\n* // returns false\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isBoolean = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isBoolean, 'isPrimitive', isPrimitive );\nsetReadOnly( isBoolean, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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// MAIN //\n\n/**\n* Returns the global object using code generation.\n*\n* @private\n* @returns {Object} global object\n*/\nfunction getGlobal() {\n\treturn new Function( 'return this;' )(); // eslint-disable-line no-new-func\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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// MAIN //\n\nvar obj = ( typeof self === 'object' ) ? self : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof window === 'object' ) ? window : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof global === 'object' ) ? global : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar getThis = require( './codegen.js' );\nvar Self = require( './self.js' );\nvar Win = require( './window.js' );\nvar Global = require( './global.js' );\n\n\n// MAIN //\n\n/**\n* Returns the global object.\n*\n* ## Notes\n*\n* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.\n*\n* @param {boolean} [codegen=false] - boolean indicating whether to use code generation to resolve the global object\n* @throws {TypeError} must provide a boolean\n* @throws {Error} unable to resolve global object\n* @returns {Object} global object\n*\n* @example\n* var g = getGlobal();\n* // returns {...}\n*/\nfunction getGlobal( codegen ) {\n\tif ( arguments.length ) {\n\t\tif ( !isBoolean( codegen ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Must provide a boolean primitive. Value: `'+codegen+'`.' );\n\t\t}\n\t\tif ( codegen ) {\n\t\t\treturn getThis();\n\t\t}\n\t\t// Fall through...\n\t}\n\t// Case: browsers and web workers\n\tif ( Self ) {\n\t\treturn Self;\n\t}\n\t// Case: browsers\n\tif ( Win ) {\n\t\treturn Win;\n\t}\n\t// Case: Node.js\n\tif ( Global ) {\n\t\treturn Global;\n\t}\n\t// Case: unknown\n\tthrow new Error( 'unexpected error. Unable to resolve global object.' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar getGlobal = require( '@stdlib/utils-global' );\n\n\n// MAIN //\n\nvar root = getGlobal();\nvar nodeList = root.document && root.document.childNodes;\n\n\n// EXPORTS //\n\nmodule.exports = nodeList;\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* Return the global object.\n*\n* @module @stdlib/utils-global\n*\n* @example\n* var getGlobal = require( '@stdlib/utils-global' );\n*\n* var g = getGlobal();\n* // returns {...}\n*/\n\n// MODULES //\n\nvar getGlobal = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar typedarray = Int8Array; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = typedarray;\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\nvar RE = require( './fixtures/re.js' );\nvar nodeList = require( './fixtures/nodelist.js' );\nvar typedarray = require( './fixtures/typedarray.js' );\n\n\n// MAIN //\n\n/**\n* Checks whether a polyfill is needed when using the `typeof` operator.\n*\n* @private\n* @returns {boolean} boolean indicating whether a polyfill is needed\n*/\nfunction check() {\n\tif (\n\t\t// Chrome 1-12 returns 'function' for regular expression instances (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof):\n\t\ttypeof RE === 'function' ||\n\n\t\t// Safari 8 returns 'object' for typed array and weak map constructors (underscore #1929):\n\t\ttypeof typedarray === 'object' ||\n\n\t\t// PhantomJS 1.9 returns 'function' for `NodeList` instances (underscore #2236):\n\t\ttypeof nodeList === 'function'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\nfunction reFunctionName() {\n\treturn /^\\s*function\\s*([^(]*)/i;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @module @stdlib/regexp-function-name\n*\n* @example\n* var reFunctionName = require( '@stdlib/regexp-function-name' );\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reFunctionName = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reFunctionName, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\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\nvar reFunctionName = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Captures everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* Regular expression: `/^\\s*function\\s*([^(]*)/i`\n*\n* - `/^\\s*`\n* - Match zero or more spaces at beginning\n*\n* - `function`\n* - Match the word `function`\n*\n* - `\\s*`\n* - Match zero or more spaces after the word `function`\n*\n* - `()`\n* - Capture\n*\n* - `[^(]*`\n* - Match anything except a left parenthesis `(` zero or more times\n*\n* - `/i`\n* - ignore case\n*\n* @constant\n* @type {RegExp}\n* @default /^\\s*function\\s*([^(]*)/i\n*/\nvar RE_FUNCTION_NAME = reFunctionName();\n\n\n// EXPORTS //\n\nmodule.exports = RE_FUNCTION_NAME;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar f;\n\n\n// FUNCTIONS //\n\n/**\n* Tests if a value is an array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an array\n*\n* @example\n* var bool = isArray( [] );\n* // returns true\n*\n* @example\n* var bool = isArray( {} );\n* // returns false\n*/\nfunction isArray( value ) {\n\treturn ( nativeClass( value ) === '[object Array]' );\n}\n\n\n// MAIN //\n\nif ( Array.isArray ) {\n\tf = Array.isArray;\n} else {\n\tf = isArray;\n}\n\n\n// EXPORTS //\n\nmodule.exports = f;\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* Test if a value is an array.\n*\n* @module @stdlib/assert-is-array\n*\n* @example\n* var isArray = require( '@stdlib/assert-is-array' );\n*\n* var bool = isArray( [] );\n* // returns true\n*\n* bool = isArray( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isArray = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isArray;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Returns a function which tests if every element in an array passes a test condition.\n*\n* @param {Function} predicate - function to apply\n* @throws {TypeError} must provide a function\n* @returns {Function} an array function\n*\n* @example\n* var isOdd = require( '@stdlib/assert-is-odd' );\n*\n* var arr1 = [ 1, 3, 5, 7 ];\n* var arr2 = [ 3, 5, 8 ];\n*\n* var validate = arrayfcn( isOdd );\n*\n* var bool = validate( arr1 );\n* // returns true\n*\n* bool = validate( arr2 );\n* // returns false\n*/\nfunction arrayfcn( predicate ) {\n\tif ( typeof predicate !== 'function' ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a function. Value: `' + predicate + '`.' );\n\t}\n\treturn every;\n\n\t/**\n\t* Tests if every element in an array passes a test condition.\n\t*\n\t* @private\n\t* @param {*} value - value to test\n\t* @returns {boolean} boolean indicating whether a value is an array for which all elements pass a test condition\n\t*/\n\tfunction every( value ) {\n\t\tvar len;\n\t\tvar i;\n\t\tif ( !isArray( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tlen = value.length;\n\t\tif ( len === 0 ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( predicate( value[ i ] ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayfcn;\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* Tests if a value is object-like.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is object-like\n*\n* @example\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( [] );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( null );\n* // returns false\n*/\nfunction isObjectLike( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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* Test if a value is object-like.\n*\n* @module @stdlib/assert-is-object-like\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' );\n*\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* bool = isObjectLike( [] );\n* // returns true\n*\n* bool = isObjectLike( null );\n* // returns false\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' ).isObjectLikeArray;\n*\n* var bool = isObjectLike( [ {}, [] ] );\n* // returns true\n*\n* bool = isObjectLike( [ {}, '3.0' ] );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar arrayfun = require( '@stdlib/assert-tools-array-function' );\nvar isObjectLike = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( isObjectLike, 'isObjectLikeArray', arrayfun( isObjectLike ) );\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Buffer instance.\n*\n* @param {*} value - value to validate\n* @returns {boolean} boolean indicating if a value is a Buffer instance\n*\n* @example\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( new Buffer( [1,2,3,4] ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( {} );\n* // returns false\n*\n* @example\n* var v = isBuffer( [] );\n* // returns false\n*/\nfunction isBuffer( value ) {\n\treturn (\n\t\tisObjectLike( value ) &&\n\t\t(\n\t\t\t// eslint-disable-next-line no-underscore-dangle\n\t\t\tvalue._isBuffer || // for envs missing Object.prototype.constructor (e.g., Safari 5-7)\n\t\t\t(\n\t\t\t\tvalue.constructor &&\n\n\t\t\t\t// WARNING: `typeof` is not a foolproof check, as certain envs consider RegExp and NodeList instances to be functions\n\t\t\t\ttypeof value.constructor.isBuffer === 'function' &&\n\t\t\t\tvalue.constructor.isBuffer( value )\n\t\t\t)\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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* Test if a value is a Buffer instance.\n*\n* @module @stdlib/assert-is-buffer\n*\n* @example\n* var isBuffer = require( '@stdlib/assert-is-buffer' );\n*\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* v = isBuffer( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isBuffer = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar RE = require( '@stdlib/regexp-function-name' ).REGEXP;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\n\n\n// MAIN //\n\n/**\n* Determines the name of a value's constructor.\n*\n* @param {*} v - input value\n* @returns {string} name of a value's constructor\n*\n* @example\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* @example\n* var v = constructorName( 5 );\n* // returns 'Number'\n*\n* @example\n* var v = constructorName( null );\n* // returns 'Null'\n*\n* @example\n* var v = constructorName( undefined );\n* // returns 'Undefined'\n*\n* @example\n* var v = constructorName( function noop() {} );\n* // returns 'Function'\n*/\nfunction constructorName( v ) {\n\tvar match;\n\tvar name;\n\tvar ctor;\n\tname = nativeClass( v ).slice( 8, -1 );\n\tif ( (name === 'Object' || name === 'Error') && v.constructor ) {\n\t\tctor = v.constructor;\n\t\tif ( typeof ctor.name === 'string' ) {\n\t\t\treturn ctor.name;\n\t\t}\n\t\tmatch = RE.exec( ctor.toString() );\n\t\tif ( match ) {\n\t\t\treturn match[ 1 ];\n\t\t}\n\t}\n\tif ( isBuffer( v ) ) {\n\t\treturn 'Buffer';\n\t}\n\treturn name;\n}\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// NOTES //\n\n/*\n* Built-in `typeof` operator behavior:\n*\n* ```text\n* typeof null => 'object'\n* typeof undefined => 'undefined'\n* typeof 'a' => 'string'\n* typeof 5 => 'number'\n* typeof NaN => 'number'\n* typeof true => 'boolean'\n* typeof false => 'boolean'\n* typeof {} => 'object'\n* typeof [] => 'object'\n* typeof function foo(){} => 'function'\n* typeof function* foo(){} => 'object'\n* typeof Symbol() => 'symbol'\n* ```\n*\n*/\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\tvar type;\n\n\t// Address `typeof null` => `object` (see http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null):\n\tif ( v === null ) {\n\t\treturn 'null';\n\t}\n\ttype = typeof v;\n\n\t// If the `typeof` operator returned something other than `object`, we are done. Otherwise, we need to check for an internal class name or search for a constructor.\n\tif ( type === 'object' ) {\n\t\treturn ctorName( v ).toLowerCase();\n\t}\n\treturn type;\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine the name of a value's constructor.\n*\n* @module @stdlib/utils-constructor-name\n*\n* @example\n* var constructorName = require( '@stdlib/utils-constructor-name' );\n*\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* v = constructorName( {} );\n* // returns 'Object'\n*\n* v = constructorName( true );\n* // returns 'Boolean'\n*/\n\n// MODULES //\n\nvar constructorName = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\treturn ctorName( v ).toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine a value's type.\n*\n* @module @stdlib/utils-type-of\n*\n* @example\n* var typeOf = require( '@stdlib/utils-type-of' );\n*\n* var str = typeOf( 'a' );\n* // returns 'string'\n*\n* str = typeOf( 5 );\n* // returns 'number'\n*/\n\n// MODULES //\n\nvar usePolyfill = require( './check.js' );\nvar typeOf = require( './typeof.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main = ( usePolyfill() ) ? polyfill : typeOf;\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar typeOf = require( '@stdlib/utils-type-of' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a function.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a function\n*\n* @example\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\nfunction isFunction( value ) {\n\t// Note: cannot use `typeof` directly, as various browser engines incorrectly return `'function'` when operating on non-function objects, such as regular expressions and NodeLists.\n\treturn ( typeOf( value ) === 'function' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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* Test if a value is a function.\n*\n* @module @stdlib/assert-is-function\n*\n* @example\n* var isFunction = require( '@stdlib/assert-is-function' );\n*\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\n\n// MODULES //\n\nvar isFunction = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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\nvar exec = require( './exec.js' );\n\n\n// MAIN //\n\n/**\n* Attempts to call a `RegExp` method.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if able to call a `RegExp` method\n*/\nfunction test( value ) {\n\ttry {\n\t\texec.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar exec = RegExp.prototype.exec; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = exec;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2exec.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a regular expression.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a regular expression\n*\n* @example\n* var bool = isRegExp( /\\.+/ );\n* // returns true\n*\n* @example\n* var bool = isRegExp( {} );\n* // returns false\n*/\nfunction isRegExp( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof RegExp ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object RegExp]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isRegExp;\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\nvar rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument argument must be a string primitive or regular expression\n* @throws {TypeError} third argument must be a string primitive or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive or regular expression. Value: `' + search + '`.' );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( 'invalid argument. Third argument must be a string primitive or replacement function. Value: `' + newval + '`.' );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Constructor which returns a `Number` object.\n*\n* @module @stdlib/number-ctor\n*\n* @example\n* var Number = require( '@stdlib/number-ctor' );\n*\n* var v = new Number( 10.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar Number = require( './number.js' );\n\n\n// EXPORTS //\n\nmodule.exports = Number;\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// EXPORTS //\n\nmodule.exports = Number; // eslint-disable-line stdlib/require-globals\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Number.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar Number = require( '@stdlib/number-ctor' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\nfunction isNumber( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Number ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Number]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a number\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( null );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Test if a value is a number.\n*\n* @module @stdlib/assert-is-number\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' );\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( null );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isObject;\n*\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNumber, 'isPrimitive', isPrimitive );\nsetReadOnly( isNumber, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Double-precision floating-point positive infinity.\n*\n* @module @stdlib/constants-float64-pinf\n* @type {number}\n*\n* @example\n* var FLOAT64_PINF = require( '@stdlib/constants-float64-pinf' );\n* // returns Infinity\n*/\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point positive infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point positive infinity has the bit sequence\n*\n* ```binarystring\n* 0 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.POSITIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_PINF = Number.POSITIVE_INFINITY; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_PINF;\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* Double-precision floating-point negative infinity.\n*\n* @module @stdlib/constants-float64-ninf\n* @type {number}\n*\n* @example\n* var FLOAT64_NINF = require( '@stdlib/constants-float64-ninf' );\n* // returns -Infinity\n*/\n\n// MODULES //\n\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point negative infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point negative infinity has the bit sequence\n*\n* ```binarystring\n* 1 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.NEGATIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_NINF = Number.NEGATIVE_INFINITY;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_NINF;\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\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Tests if a finite double-precision floating-point number is an integer.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\treturn (floor(x) === x);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// TODO: implementation (?)\n\n/**\n* Rounds a double-precision floating-point number toward negative infinity.\n*\n* @param {number} x - input value\n* @returns {number} rounded value\n*\n* @example\n* var v = floor( -4.2 );\n* // returns -5.0\n*\n* @example\n* var v = floor( 9.99999 );\n* // returns 9.0\n*\n* @example\n* var v = floor( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = floor( NaN );\n* // returns NaN\n*/\nvar floor = Math.floor; // eslint-disable-line stdlib/no-builtin-math\n\n\n// EXPORTS //\n\nmodule.exports = floor;\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* Test if a finite double-precision floating-point number is an integer.\n*\n* @module @stdlib/math-base-assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/math-base-assert-is-integer' );\n*\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* bool = isInteger( 3.14 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isInteger = require( './is_integer.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar isInt = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests if a number primitive is an integer value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a number primitive is an integer value\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tvalue < PINF &&\n\t\tvalue > NINF &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having an integer value\n*\n* @example\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having an integer value\n*\n* @example\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an integer\n*\n* @example\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isInteger( -3.14 );\n* // returns false\n*\n* @example\n* var bool = isInteger( null );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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* Test if a value is an integer.\n*\n* @module @stdlib/assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/assert-is-integer' );\n*\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isInteger( -3.14 );\n* // returns false\n*\n* bool = isInteger( null );\n* // returns false\n*\n* @example\n* // Use interface to check for integer primitives...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n*\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*\n* @example\n* // Use interface to check for integer objects...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n*\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue.valueOf() >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a nonnegative integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a nonnegative integer\n*\n* @example\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( null );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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* Test if a value is a nonnegative integer.\n*\n* @module @stdlib/assert-is-nonnegative-integer\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' );\n*\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* bool = isNonNegativeInteger( null );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isObject;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNonNegativeInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isNonNegativeInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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// MAIN //\n\nvar getProto = Object.getPrototypeOf;\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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* Returns the value of the `__proto__` property.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {*} value of `__proto__` property\n*/\nfunction getProto( obj ) {\n\t// eslint-disable-next-line no-proto\n\treturn obj.__proto__;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar getProto = require( './proto.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {(Object|null)} prototype\n*/\nfunction getPrototypeOf( obj ) {\n\tvar proto = getProto( obj );\n\tif ( proto || proto === null ) {\n\t\treturn proto;\n\t}\n\tif ( nativeClass( obj.constructor ) === '[object Function]' ) {\n\t\t// May break if the constructor has been tampered with...\n\t\treturn obj.constructor.prototype;\n\t}\n\tif ( obj instanceof Object ) {\n\t\treturn Object.prototype;\n\t}\n\t// Return `null` for objects created via `Object.create( null )`. Also return `null` for cross-realm objects on browsers that lack `__proto__` support, such as IE < 11.\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar builtin = require( './native.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar getProto;\nif ( isFunction( Object.getPrototypeOf ) ) {\n\tgetProto = builtin;\n} else {\n\tgetProto = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar getProto = require( './detect.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @param {*} value - input value\n* @returns {(Object|null)} prototype\n*\n* @example\n* var proto = getPrototypeOf( {} );\n* // returns {}\n*/\nfunction getPrototypeOf( value ) {\n\tif (\n\t\tvalue === null ||\n\t\tvalue === void 0\n\t) {\n\t\treturn null;\n\t}\n\t// In order to ensure consistent ES5/ES6 behavior, cast input value to an object (strings, numbers, booleans); ES5 `Object.getPrototypeOf` throws when provided primitives and ES6 `Object.getPrototypeOf` casts:\n\tvalue = Object( value );\n\n\treturn getProto( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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* Return the prototype of a provided object.\n*\n* @module @stdlib/utils-get-prototype-of\n*\n* @example\n* var getPrototype = require( '@stdlib/utils-get-prototype-of' );\n*\n* var proto = getPrototype( {} );\n* // returns {}\n*/\n\n// MODULES //\n\nvar getPrototype = require( './get_prototype_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getPrototype;\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\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an `Error` object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `Error` object\n*\n* @example\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isError( {} );\n* // returns false\n*/\nfunction isError( value ) {\n\tif ( typeof value !== 'object' || value === null ) {\n\t\treturn false;\n\t}\n\t// Check for `Error` objects from the same realm (same Node.js `vm` or same `Window` object)...\n\tif ( value instanceof Error ) {\n\t\treturn true;\n\t}\n\t// Walk the prototype tree until we find an object having the desired native class...\n\twhile ( value ) {\n\t\tif ( nativeClass( value ) === '[object Error]' ) {\n\t\t\treturn true;\n\t\t}\n\t\tvalue = getPrototypeOf( value );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isError;\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* Test if a value is an `Error` object.\n*\n* @module @stdlib/assert-is-error\n*\n* @example\n* var isError = require( '@stdlib/assert-is-error' );\n*\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* bool = isError( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isError = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isError;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to parse a regular expression string.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*/\nfunction reRegExp() {\n\treturn /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/; // eslint-disable-line no-useless-escape\n}\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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* Return a regular expression to parse a regular expression string.\n*\n* @module @stdlib/regexp-regexp\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var parts = RE_REGEXP.exec( '/^.*$/ig' );\n* // returns [ '/^.*$/ig', '^.*$', 'ig', 'index': 0, 'input': '/^.*$/ig' ]\n*/\n\n// MAIN //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reRegExp = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reRegExp, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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\nvar reRegExp = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Matches parts of a regular expression string.\n*\n* Regular expression: `/^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/`\n*\n* - `/^\\/`\n* - match a string that begins with a `/`\n*\n* - `()`\n* - capture\n*\n* - `(?:)+`\n* - capture, but do not remember, a group of characters which occur one or more times\n*\n* - `\\\\\\/`\n* - match the literal `\\/`\n*\n* - `|`\n* - OR\n*\n* - `[^\\/]`\n* - anything which is not the literal `\\/`\n*\n* - `\\/`\n* - match the literal `/`\n*\n* - `([imgy]*)`\n* - capture any characters matching `imgy` occurring zero or more times\n*\n* - `$/`\n* - string end\n*\n*\n* @constant\n* @type {RegExp}\n* @default /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/\n*/\nvar RE_REGEXP = reRegExp();\n\n\n// EXPORTS //\n\nmodule.exports = RE_REGEXP;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar reRegExp = require( '@stdlib/regexp-regexp' );\n\n\n// MAIN //\n\n/**\n* Parses a regular expression string and returns a new regular expression.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} must provide a regular expression string\n* @returns {(RegExp|null)} regular expression or null\n*\n* @example\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\nfunction reFromString( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Capture the regular expression pattern and any flags:\n\tstr = reRegExp().exec( str );\n\n\t// Create a new regular expression:\n\treturn ( str ) ? new RegExp( str[1], str[2] ) : null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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* Create a regular expression from a regular expression string.\n*\n* @module @stdlib/utils-regexp-from-string\n*\n* @example\n* var reFromString = require( '@stdlib/utils-regexp-from-string' );\n*\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\n\n// MODULES //\n\nvar reFromString = require( './from_string.js' );\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is `NaN`.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 7.0 );\n* // returns false\n*/\nfunction isnan( x ) {\n\treturn ( x !== x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a `NaN` number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a `NaN` number primitive\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a double-precision floating-point numeric value is `NaN`.\n*\n* @module @stdlib/math-base-assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/math-base-assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 7.0 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isnan = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a value of `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a value of `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( null );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a value is `NaN`.\n*\n* @module @stdlib/assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( null );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isObject;\n*\n* var bool = isnan( NaN );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isnan = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isnan, 'isPrimitive', isPrimitive );\nsetReadOnly( isnan, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a collection.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is a collection\n*\n* @example\n* var bool = isCollection( [] );\n* // returns true\n*\n* @example\n* var bool = isCollection( {} );\n* // returns false\n*/\nfunction isCollection( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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\nvar isnan = require( '@stdlib/assert-is-nan' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Returns the first index at which a given element can be found.\n*\n* @param {ArrayLike} arr - array-like object\n* @param {*} searchElement - element to find\n* @param {integer} [fromIndex] - starting index (if negative, the start index is determined relative to last element)\n* @throws {TypeError} must provide an array-like object\n* @throws {TypeError} `fromIndex` must be an integer\n* @returns {integer} index or -1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 5 );\n* // returns -1\n*\n* @example\n* // Using a `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* @example\n* // `fromIndex` which exceeds `array` length:\n* var arr = [ 1, 2, 3, 4, 2, 5 ];\n* var idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* @example\n* // Negative `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* var idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* @example\n* // Negative `fromIndex` exceeding input `array` length:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* @example\n* // Array-like objects:\n* var str = 'bebop';\n* var idx = indexOf( str, 'o' );\n* // returns 3\n*/\nfunction indexOf( arr, searchElement, fromIndex ) {\n\tvar len;\n\tvar i;\n\tif ( !isCollection( arr ) && !isString( arr ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array-like object. Value: `' + arr + '`.' );\n\t}\n\tlen = arr.length;\n\tif ( len === 0 ) {\n\t\treturn -1;\n\t}\n\tif ( arguments.length === 3 ) {\n\t\tif ( !isInteger( fromIndex ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `fromIndex` must be an integer. Value: `' + fromIndex + '`.' );\n\t\t}\n\t\tif ( fromIndex >= 0 ) {\n\t\t\tif ( fromIndex >= len ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\ti = fromIndex;\n\t\t} else {\n\t\t\ti = len + fromIndex;\n\t\t\tif ( i < 0 ) {\n\t\t\t\ti = 0;\n\t\t\t}\n\t\t}\n\t} else {\n\t\ti = 0;\n\t}\n\t// Check for `NaN`...\n\tif ( isnan( searchElement ) ) {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( isnan( arr[i] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( arr[ i ] === searchElement ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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* Maximum length of a typed array.\n*\n* @module @stdlib/constants-array-max-typed-array-length\n*\n* @example\n* var MAX_TYPED_ARRAY_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n* // returns 9007199254740991\n*/\n\n// MAIN //\n\n/**\n* Maximum length of a typed array.\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n*/\nvar MAX_TYPED_ARRAY_LENGTH = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = MAX_TYPED_ARRAY_LENGTH;\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* Return the first index at which a given element can be found.\n*\n* @module @stdlib/utils-index-of\n*\n* @example\n* var indexOf = require( '@stdlib/utils-index-of' );\n*\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* arr = [ 4, 3, 2, 1 ];\n* idx = indexOf( arr, 5 );\n* // returns -1\n*\n* // Using a `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* // `fromIndex` which exceeds `array` length:\n* arr = [ 1, 2, 3, 4, 2, 5 ];\n* idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* // Negative `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* // Negative `fromIndex` exceeding input `array` length:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* // Array-like objects:\n* var str = 'bebop';\n* idx = indexOf( str, 'o' );\n* // returns 3\n*/\n\n// MODULES //\n\nvar indexOf = require( './index_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.keys()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\treturn Object.keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar keys = require( './builtin.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests the built-in `Object.keys()` implementation when provided `arguments`.\n*\n* @private\n* @returns {boolean} boolean indicating whether the built-in implementation returns the expected number of keys\n*/\nfunction test() {\n\treturn ( keys( arguments ) || '' ).length !== 2;\n}\n\n\n// MAIN //\n\n/**\n* Tests whether the built-in `Object.keys()` implementation supports providing `arguments` as an input value.\n*\n* ## Notes\n*\n* - Safari 5.0 does **not** support `arguments` as an input value.\n*\n* @private\n* @returns {boolean} boolean indicating whether a built-in implementation supports `arguments`\n*/\nfunction check() {\n\treturn test( 1, 2 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\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// MAIN //\n\nvar bool = ( typeof Object.keys !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn ( nativeClass( value ) === '[object Arguments]' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( './main.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment returns the expected internal class of the `arguments` object.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment behaves as expected\n*\n* @example\n* var bool = detect();\n* // returns \n*/\nfunction detect() {\n\treturn isArguments( arguments );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnum = require( './native.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment has a bug where String indices are not detected as \"enumerable\" properties. Observed in Node v0.10.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment has the bug\n*/\nfunction detect() {\n\treturn !isEnum.call( 'beep', '0' );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @private\n* @name isEnumerableProperty\n* @type {Function}\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nvar isEnumerableProperty = Object.prototype.propertyIsEnumerable;\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar isString = require( '@stdlib/assert-is-string' );\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isEnum = require( './native.js' );\nvar hasStringEnumBug = require( './has_string_enumerability_bug.js' );\n\n\n// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nfunction isEnumerableProperty( value, property ) {\n\tvar bool;\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\tbool = isEnum.call( value, property );\n\tif ( !bool && hasStringEnumBug && isString( value ) ) {\n\t\t// Note: we only check for indices, as properties attached to a `String` object are properly detected as enumerable above.\n\t\tproperty = +property;\n\t\treturn (\n\t\t\t!isnan( property ) &&\n\t\t\tisInteger( property ) &&\n\t\t\tproperty >= 0 &&\n\t\t\tproperty < value.length\n\t\t);\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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* Test whether an object's own property is enumerable.\n*\n* @module @stdlib/assert-is-enumerable-property\n*\n* @example\n* var isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\n\n// MODULES //\n\nvar isEnumerableProperty = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-uint32-max' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object' &&\n\t\t!isArray( value ) &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH &&\n\t\thasOwnProp( value, 'callee' ) &&\n\t\t!isEnumerableProperty( value, 'callee' )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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* Test if a value is an `arguments` object.\n*\n* @module @stdlib/assert-is-arguments\n*\n* @example\n* var isArguments = require( '@stdlib/assert-is-arguments' );\n*\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* bool = isArguments( [] );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasArgumentsClass = require( './detect.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar isArguments;\nif ( hasArgumentsClass ) {\n\tisArguments = main;\n} else {\n\tisArguments = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar builtin = require( './builtin.js' );\n\n\n// VARIABLES //\n\nvar slice = Array.prototype.slice;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tif ( isArguments( value ) ) {\n\t\treturn builtin( slice.call( value ) );\n\t}\n\treturn builtin( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* No operation.\n*\n* @example\n* noop();\n* // ...does nothing.\n*/\nfunction noop() {\n\t// Empty function...\n}\n\n\n// EXPORTS //\n\nmodule.exports = noop;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar noop = require( '@stdlib/utils-noop' );\n\n\n// MAIN //\n\n// Note: certain environments treat an object's prototype as enumerable, which, as a matter of convention, it shouldn't be...\nvar bool = isEnumerableProperty( noop, 'prototype' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n\n\n// VARIABLES //\n\nvar obj = {\n\t'toString': null\n};\n\n\n// MAIN //\n\n// Note: certain environments don't allow enumeration of overwritten properties which are considered non-enumerable...\nvar bool = !isEnumerableProperty( obj, 'toString' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests whether a value equals the prototype of its constructor.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction isConstructorPrototype( value ) {\n\treturn ( value.constructor && value.constructor.prototype === value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isConstructorPrototype;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar EXCLUDED_KEYS = require( './excluded_keys.json' );\nvar win = require( './window.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Determines whether an environment throws when comparing to the prototype of a value's constructor (e.g., [IE9][1]).\n*\n* [1]: https://stackoverflow.com/questions/7688070/why-is-comparing-the-constructor-property-of-two-windows-unreliable\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment is buggy\n*/\nfunction check() {\n\tvar k;\n\tif ( typeOf( win ) === 'undefined' ) {\n\t\treturn false;\n\t}\n\tfor ( k in win ) { // eslint-disable-line guard-for-in\n\t\ttry {\n\t\t\tif (\n\t\t\t\tindexOf( EXCLUDED_KEYS, k ) === -1 &&\n\t\t\t\thasOwnProp( win, k ) &&\n\t\t\t\twin[ k ] !== null &&\n\t\t\t\ttypeOf( win[ k ] ) === 'object'\n\t\t\t) {\n\t\t\t\tisConstructorPrototype( win[ k ] );\n\t\t\t}\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// MAIN //\n\nbool = check();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\nvar w = ( typeof window === 'undefined' ) ? void 0 : window;\n\n\n// EXPORTS //\n\nmodule.exports = w;\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// MAIN //\n\nvar bool = ( typeof window !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar hasAutomationEqualityBug = require( './has_automation_equality_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar HAS_WINDOW = require( './has_window.js' );\n\n\n// MAIN //\n\n/**\n* Wraps the test for constructor prototype equality to accommodate buggy environments (e.g., environments which throw when testing equality).\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction wrapper( value ) {\n\tif ( HAS_WINDOW === false && !hasAutomationEqualityBug ) {\n\t\treturn isConstructorPrototype( value );\n\t}\n\ttry {\n\t\treturn isConstructorPrototype( value );\n\t} catch ( error ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = wrapper;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar HAS_ENUM_PROTO_BUG = require( './has_enumerable_prototype_bug.js' );\nvar HAS_NON_ENUM_PROPS_BUG = require( './has_non_enumerable_properties_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype_wrapper.js' );\nvar NON_ENUMERABLE = require( './non_enumerable.json' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tvar skipConstructor;\n\tvar skipPrototype;\n\tvar isFcn;\n\tvar out;\n\tvar k;\n\tvar p;\n\tvar i;\n\n\tout = [];\n\tif ( isArguments( value ) ) {\n\t\t// Account for environments which treat `arguments` differently...\n\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\tout.push( i.toString() );\n\t\t}\n\t\t// Note: yes, we are precluding the `arguments` array-like object from having other enumerable properties; however, this should (1) be very rare and (2) not be encouraged (e.g., doing something like `arguments.a = 'b'`; in certain engines directly manipulating the `arguments` value results in automatic de-optimization).\n\t\treturn out;\n\t}\n\tif ( typeof value === 'string' ) {\n\t\t// Account for environments which do not treat string character indices as \"own\" properties...\n\t\tif ( value.length > 0 && !hasOwnProp( value, '0' ) ) {\n\t\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\t\tout.push( i.toString() );\n\t\t\t}\n\t\t}\n\t} else {\n\t\tisFcn = ( typeof value === 'function' );\n\t\tif ( isFcn === false && !isObjectLike( value ) ) {\n\t\t\treturn out;\n\t\t}\n\t\tskipPrototype = ( HAS_ENUM_PROTO_BUG && isFcn );\n\t}\n\tfor ( k in value ) {\n\t\tif ( !( skipPrototype && k === 'prototype' ) && hasOwnProp( value, k ) ) {\n\t\t\tout.push( String( k ) );\n\t\t}\n\t}\n\tif ( HAS_NON_ENUM_PROPS_BUG ) {\n\t\tskipConstructor = isConstructorPrototype( value );\n\t\tfor ( i = 0; i < NON_ENUMERABLE.length; i++ ) {\n\t\t\tp = NON_ENUMERABLE[ i ];\n\t\t\tif ( !( skipConstructor && p === 'constructor' ) && hasOwnProp( value, p ) ) {\n\t\t\t\tout.push( String( p ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar hasArgumentsBug = require( './has_arguments_bug.js' );\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar wrapper = require( './builtin_wrapper.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @name keys\n* @type {Function}\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nvar keys;\nif ( HAS_BUILTIN ) {\n\tif ( hasArgumentsBug() ) {\n\t\tkeys = wrapper;\n\t} else {\n\t\tkeys = builtin;\n\t}\n} else {\n\tkeys = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* Return an array of an object's own enumerable property names.\n*\n* @module @stdlib/utils-keys\n*\n* @example\n* var keys = require( '@stdlib/utils-keys' );\n*\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\n\n// MODULES //\n\nvar keys = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyNames !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyNames = Object.getOwnPropertyNames;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn propertyNames( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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\nvar keys = require( '@stdlib/utils-keys' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n* - In environments lacking support for `Object.getOwnPropertyNames()`, property descriptors are unavailable, and thus all properties can be safely assumed to be enumerable. Hence, we can defer to calling `Object.keys`, which retrieves all own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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* Return an array of an object's own enumerable and non-enumerable property names.\n*\n* @module @stdlib/utils-property-names\n*\n* @example\n* var getOwnPropertyNames = require( '@stdlib/utils-property-names' );\n*\n* var keys = getOwnPropertyNames({\n* 'foo': 'bar',\n* 'beep': 'boop'\n* });\n* // e.g., returns [ 'foo', 'beep' ]\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyDescriptor !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyDescriptor = Object.getOwnPropertyDescriptor;\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tvar desc;\n\tif ( value === null || value === void 0 ) {\n\t\treturn null;\n\t}\n\tdesc = propertyDescriptor( value, property );\n\treturn ( desc === void 0 ) ? null : desc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n* - In environments lacking `Object.getOwnPropertyDescriptor()` support, property descriptors do not exist. In non-supporting environment, if an object has a provided property, this function returns a descriptor object equivalent to that returned in a supporting environment; otherwise, the function returns `null`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tif ( hasOwnProp( value, property ) ) {\n\t\treturn {\n\t\t\t'configurable': true,\n\t\t\t'enumerable': true,\n\t\t\t'writable': true,\n\t\t\t'value': value[ property ]\n\t\t};\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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* Return a property descriptor for an object's own property.\n*\n* @module @stdlib/utils-property-descriptor\n*\n* @example\n* var getOwnPropertyDescriptor = require( '@stdlib/utils-property-descriptor' );\n*\n* var obj = {\n* 'foo': 'bar',\n* 'beep': 'boop'\n* };\n*\n* var keys = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':'bar'}\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar main = ( typeof Buffer === 'function' ) ? Buffer : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar GlobalBuffer = require( './buffer.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Buffer` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Buffer` support\n*\n* @example\n* var bool = hasNodeBufferSupport();\n* // returns \n*/\nfunction hasNodeBufferSupport() {\n\tvar bool;\n\tvar b;\n\n\tif ( typeof GlobalBuffer !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tif ( typeof GlobalBuffer.from === 'function' ) {\n\t\t\tb = GlobalBuffer.from( [ 1, 2, 3, 4 ] );\n\t\t} else {\n\t\t\tb = new GlobalBuffer( [ 1, 2, 3, 4 ] ); // Note: this is deprecated behavior starting in Node v6 (see https://nodejs.org/api/buffer.html#buffer_new_buffer_array)\n\t\t}\n\t\tbool = (\n\t\t\tisBuffer( b ) &&\n\t\t\tb[ 0 ] === 1 &&\n\t\t\tb[ 1 ] === 2 &&\n\t\t\tb[ 2 ] === 3 &&\n\t\t\tb[ 3 ] === 4\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasNodeBufferSupport;\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* Test for native `Buffer` support.\n*\n* @module @stdlib/assert-has-node-buffer-support\n*\n* @example\n* var hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\n*\n* var bool = hasNodeBufferSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasNodeBufferSupport;\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// TODO: write (browser) polyfill\n\n// MAIN //\n\n/**\n* Buffer constructor.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Buffer constructor.\n*\n* @module @stdlib/buffer-ctor\n*\n* @example\n* var ctor = require( '@stdlib/buffer-ctor' );\n*\n* var b = new ctor( [ 1, 2, 3, 4 ] );\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\nvar main = require( './buffer.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasNodeBufferSupport() ) {\n\tctor = main;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = require( 'buffer' ).Buffer; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\nvar bool = isFunction( Buffer.from );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn Buffer.from( buffer );\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn new Buffer( buffer ); // eslint-disable-line no-buffer-constructor\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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* Copy buffer data to a new `Buffer` instance.\n*\n* @module @stdlib/buffer-from-buffer\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n* var copyBuffer = require( '@stdlib/buffer-from-buffer' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = copyBuffer( b1 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFrom = require( './has_from.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar copyBuffer;\nif ( hasFrom ) {\n\tcopyBuffer = main;\n} else {\n\tcopyBuffer = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt8Array = ( typeof Int8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int8Array\n*\n* @example\n* var bool = isInt8Array( new Int8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt8Array( [] );\n* // returns false\n*/\nfunction isInt8Array( value ) {\n\treturn (\n\t\t( hasInt8Array && value instanceof Int8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt8Array;\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// MAIN //\n\nvar main = ( typeof Int8Array === 'function' ) ? Int8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt8Array = require( '@stdlib/assert-is-int8array' );\nvar INT8_MAX = require( '@stdlib/constants-int8-max' );\nvar INT8_MIN = require( '@stdlib/constants-int8-min' );\nvar GlobalInt8Array = require( './int8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int8Array` support\n*\n* @example\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\nfunction hasInt8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt8Array( [ 1, 3.14, -3.14, INT8_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT8_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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* Minimum signed 8-bit integer.\n*\n* @module @stdlib/constants-int8-min\n* @type {integer32}\n*\n* @example\n* var INT8_MIN = require( '@stdlib/constants-int8-min' );\n* // returns -128\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 8-bit integer.\n*\n* ## Notes\n*\n* The number is given by\n*\n* ```tex\n* -(2^{7})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -128\n*/\nvar INT8_MIN = -128|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT8_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int8\n*\n* @example\n* var ctor = require( '@stdlib/array-int8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\nvar builtin = require( './int8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int8Array === 'function' ) ? Int8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int8Array` support.\n*\n* @module @stdlib/assert-has-int8array-support\n*\n* @example\n* var hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\n*\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8Array = ( typeof Uint8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8Array\n*\n* @example\n* var bool = isUint8Array( new Uint8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8Array( [] );\n* // returns false\n*/\nfunction isUint8Array( value ) {\n\treturn (\n\t\t( hasUint8Array && value instanceof Uint8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8Array;\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// MAIN //\n\nvar main = ( typeof Uint8Array === 'function' ) ? Uint8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8Array = require( '@stdlib/assert-is-uint8array' );\nvar UINT8_MAX = require( '@stdlib/constants-uint8-max' );\nvar GlobalUint8Array = require( './uint8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8Array` support\n*\n* @example\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\nfunction hasUint8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT8_MAX+1, UINT8_MAX+2 ];\n\t\tarr = new GlobalUint8Array( arr );\n\t\tbool = (\n\t\t\tisUint8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT8_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint8\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\nvar builtin = require( './uint8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8Array === 'function' ) ? Uint8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8Array` support.\n*\n* @module @stdlib/assert-has-uint8array-support\n*\n* @example\n* var hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\n*\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8ClampedArray = ( typeof Uint8ClampedArray === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8ClampedArray.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8ClampedArray\n*\n* @example\n* var bool = isUint8ClampedArray( new Uint8ClampedArray( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8ClampedArray( [] );\n* // returns false\n*/\nfunction isUint8ClampedArray( value ) {\n\treturn (\n\t\t( hasUint8ClampedArray && value instanceof Uint8ClampedArray ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8ClampedArray]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8ClampedArray;\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// MAIN //\n\nvar main = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8ClampedArray = require( '@stdlib/assert-is-uint8clampedarray' );\nvar GlobalUint8ClampedArray = require( './uint8clampedarray.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8ClampedArray` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8ClampedArray` support\n*\n* @example\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\nfunction hasUint8ClampedArraySupport() { // eslint-disable-line id-length\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8ClampedArray !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalUint8ClampedArray( [ -1, 0, 1, 3.14, 4.99, 255, 256 ] );\n\t\tbool = (\n\t\t\tisUint8ClampedArray( arr ) &&\n\t\t\tarr[ 0 ] === 0 && // clamped\n\t\t\tarr[ 1 ] === 0 &&\n\t\t\tarr[ 2 ] === 1 &&\n\t\t\tarr[ 3 ] === 3 && // round to nearest\n\t\t\tarr[ 4 ] === 5 && // round to nearest\n\t\t\tarr[ 5 ] === 255 &&\n\t\t\tarr[ 6 ] === 255 // clamped\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @module @stdlib/array-uint8c\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8c' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' ); // eslint-disable-line id-length\nvar builtin = require( './uint8clampedarray.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ClampedArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8ClampedArray` support.\n*\n* @module @stdlib/assert-has-uint8clampedarray-support\n*\n* @example\n* var hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' );\n*\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt16Array = ( typeof Int16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int16Array\n*\n* @example\n* var bool = isInt16Array( new Int16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt16Array( [] );\n* // returns false\n*/\nfunction isInt16Array( value ) {\n\treturn (\n\t\t( hasInt16Array && value instanceof Int16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt16Array;\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// MAIN //\n\nvar main = ( typeof Int16Array === 'function' ) ? Int16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt16Array = require( '@stdlib/assert-is-int16array' );\nvar INT16_MAX = require( '@stdlib/constants-int16-max' );\nvar INT16_MIN = require( '@stdlib/constants-int16-min' );\nvar GlobalInt16Array = require( './int16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int16Array` support\n*\n* @example\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\nfunction hasInt16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt16Array( [ 1, 3.14, -3.14, INT16_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT16_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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* Minimum signed 16-bit integer.\n*\n* @module @stdlib/constants-int16-min\n* @type {integer32}\n*\n* @example\n* var INT16_MIN = require( '@stdlib/constants-int16-min' );\n* // returns -32768\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 16-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{15})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 1000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -32768\n*/\nvar INT16_MIN = -32768|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT16_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int16\n*\n* @example\n* var ctor = require( '@stdlib/array-int16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\nvar builtin = require( './int16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int16Array === 'function' ) ? Int16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int16Array` support.\n*\n* @module @stdlib/assert-has-int16array-support\n*\n* @example\n* var hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\n*\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint16Array = ( typeof Uint16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint16Array\n*\n* @example\n* var bool = isUint16Array( new Uint16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint16Array( [] );\n* // returns false\n*/\nfunction isUint16Array( value ) {\n\treturn (\n\t\t( hasUint16Array && value instanceof Uint16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint16Array;\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// MAIN //\n\nvar main = ( typeof Uint16Array === 'function' ) ? Uint16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint16Array = require( '@stdlib/assert-is-uint16array' );\nvar UINT16_MAX = require( '@stdlib/constants-uint16-max' );\nvar GlobalUint16Array = require( './uint16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint16Array` support\n*\n* @example\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\nfunction hasUint16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT16_MAX+1, UINT16_MAX+2 ];\n\t\tarr = new GlobalUint16Array( arr );\n\t\tbool = (\n\t\t\tisUint16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT16_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 16-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint16\n*\n* @example\n* var ctor = require( '@stdlib/array-uint16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\nvar builtin = require( './uint16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint16Array === 'function' ) ? Uint16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint16Array` support.\n*\n* @module @stdlib/assert-has-uint16array-support\n*\n* @example\n* var hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\n*\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt32Array = ( typeof Int32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int32Array\n*\n* @example\n* var bool = isInt32Array( new Int32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt32Array( [] );\n* // returns false\n*/\nfunction isInt32Array( value ) {\n\treturn (\n\t\t( hasInt32Array && value instanceof Int32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt32Array;\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// MAIN //\n\nvar main = ( typeof Int32Array === 'function' ) ? Int32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt32Array = require( '@stdlib/assert-is-int32array' );\nvar INT32_MAX = require( '@stdlib/constants-int32-max' );\nvar INT32_MIN = require( '@stdlib/constants-int32-min' );\nvar GlobalInt32Array = require( './int32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int32Array` support\n*\n* @example\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\nfunction hasInt32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt32Array( [ 1, 3.14, -3.14, INT32_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT32_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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* Minimum signed 32-bit integer.\n*\n* @module @stdlib/constants-int32-min\n* @type {integer32}\n*\n* @example\n* var INT32_MIN = require( '@stdlib/constants-int32-min' );\n* // returns -2147483648\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 32-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{31})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -2147483648\n*/\nvar INT32_MIN = -2147483648|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT32_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int32\n*\n* @example\n* var ctor = require( '@stdlib/array-int32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\nvar builtin = require( './int32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int32Array === 'function' ) ? Int32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int32Array` support.\n*\n* @module @stdlib/assert-has-int32array-support\n*\n* @example\n* var hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\n*\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint32Array = ( typeof Uint32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint32Array\n*\n* @example\n* var bool = isUint32Array( new Uint32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint32Array( [] );\n* // returns false\n*/\nfunction isUint32Array( value ) {\n\treturn (\n\t\t( hasUint32Array && value instanceof Uint32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint32Array;\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// MAIN //\n\nvar main = ( typeof Uint32Array === 'function' ) ? Uint32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint32Array = require( '@stdlib/assert-is-uint32array' );\nvar UINT32_MAX = require( '@stdlib/constants-uint32-max' );\nvar GlobalUint32Array = require( './uint32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint32Array` support\n*\n* @example\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\nfunction hasUint32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT32_MAX+1, UINT32_MAX+2 ];\n\t\tarr = new GlobalUint32Array( arr );\n\t\tbool = (\n\t\t\tisUint32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT32_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 32-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint32\n*\n* @example\n* var ctor = require( '@stdlib/array-uint32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\nvar builtin = require( './uint32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint32Array === 'function' ) ? Uint32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint32Array` support.\n*\n* @module @stdlib/assert-has-uint32array-support\n*\n* @example\n* var hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\n*\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat32Array = ( typeof Float32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float32Array\n*\n* @example\n* var bool = isFloat32Array( new Float32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat32Array( [] );\n* // returns false\n*/\nfunction isFloat32Array( value ) {\n\treturn (\n\t\t( hasFloat32Array && value instanceof Float32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat32Array;\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// MAIN //\n\nvar main = ( typeof Float32Array === 'function' ) ? Float32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat32Array = require( '@stdlib/assert-is-float32array' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar GlobalFloat32Array = require( './float32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float32Array` support\n*\n* @example\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\nfunction hasFloat32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat32Array( [ 1.0, 3.14, -3.14, 5.0e40 ] );\n\t\tbool = (\n\t\t\tisFloat32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.140000104904175 &&\n\t\t\tarr[ 2 ] === -3.140000104904175 &&\n\t\t\tarr[ 3 ] === PINF\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of single-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float32\n*\n* @example\n* var ctor = require( '@stdlib/array-float32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\nvar builtin = require( './float32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float32Array === 'function' ) ? Float32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float32Array` support.\n*\n* @module @stdlib/assert-has-float32array-support\n*\n* @example\n* var hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\n*\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat64Array = ( typeof Float64Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float64Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float64Array\n*\n* @example\n* var bool = isFloat64Array( new Float64Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat64Array( [] );\n* // returns false\n*/\nfunction isFloat64Array( value ) {\n\treturn (\n\t\t( hasFloat64Array && value instanceof Float64Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float64Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat64Array;\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// MAIN //\n\nvar main = ( typeof Float64Array === 'function' ) ? Float64Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat64Array = require( '@stdlib/assert-is-float64array' );\nvar GlobalFloat64Array = require( './float64array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float64Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float64Array` support\n*\n* @example\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\nfunction hasFloat64ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat64Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat64Array( [ 1.0, 3.14, -3.14, NaN ] );\n\t\tbool = (\n\t\t\tisFloat64Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.14 &&\n\t\t\tarr[ 2 ] === -3.14 &&\n\t\t\tarr[ 3 ] !== arr[ 3 ]\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of double-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float64\n*\n* @example\n* var ctor = require( '@stdlib/array-float64' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\nvar builtin = require( './float64array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat64ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float64Array === 'function' ) ? Float64Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float64Array` support.\n*\n* @module @stdlib/assert-has-float64array-support\n*\n* @example\n* var hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\n*\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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\nvar Int8Array = require( '@stdlib/array-int8' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar Uint8ClampedArray = require( '@stdlib/array-uint8c' );\nvar Int16Array = require( '@stdlib/array-int16' );\nvar Uint16Array = require( '@stdlib/array-uint16' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar Uint32Array = require( '@stdlib/array-uint32' );\nvar Float32Array = require( '@stdlib/array-float32' );\nvar Float64Array = require( '@stdlib/array-float64' );\n\n\n// VARIABLES //\n\nvar hash;\n\n\n// FUNCTIONS //\n\n/**\n* Copies an `Int8Array`.\n*\n* @private\n* @param {Int8Array} arr - array to copy\n* @returns {Int8Array} new array\n*/\nfunction int8array( arr ) {\n\treturn new Int8Array( arr );\n}\n\n/**\n* Copies a `Uint8Array`.\n*\n* @private\n* @param {Uint8Array} arr - array to copy\n* @returns {Uint8Array} new array\n*/\nfunction uint8array( arr ) {\n\treturn new Uint8Array( arr );\n}\n\n/**\n* Copies a `Uint8ClampedArray`.\n*\n* @private\n* @param {Uint8ClampedArray} arr - array to copy\n* @returns {Uint8ClampedArray} new array\n*/\nfunction uint8clampedarray( arr ) {\n\treturn new Uint8ClampedArray( arr );\n}\n\n/**\n* Copies an `Int16Array`.\n*\n* @private\n* @param {Int16Array} arr - array to copy\n* @returns {Int16Array} new array\n*/\nfunction int16array( arr ) {\n\treturn new Int16Array( arr );\n}\n\n/**\n* Copies a `Uint16Array`.\n*\n* @private\n* @param {Uint16Array} arr - array to copy\n* @returns {Uint16Array} new array\n*/\nfunction uint16array( arr ) {\n\treturn new Uint16Array( arr );\n}\n\n/**\n* Copies an `Int32Array`.\n*\n* @private\n* @param {Int32Array} arr - array to copy\n* @returns {Int32Array} new array\n*/\nfunction int32array( arr ) {\n\treturn new Int32Array( arr );\n}\n\n/**\n* Copies a `Uint32Array`.\n*\n* @private\n* @param {Uint32Array} arr - array to copy\n* @returns {Uint32Array} new array\n*/\nfunction uint32array( arr ) {\n\treturn new Uint32Array( arr );\n}\n\n/**\n* Copies a `Float32Array`.\n*\n* @private\n* @param {Float32Array} arr - array to copy\n* @returns {Float32Array} new array\n*/\nfunction float32array( arr ) {\n\treturn new Float32Array( arr );\n}\n\n/**\n* Copies a `Float64Array`.\n*\n* @private\n* @param {Float64Array} arr - array to copy\n* @returns {Float64Array} new array\n*/\nfunction float64array( arr ) {\n\treturn new Float64Array( arr );\n}\n\n/**\n* Returns a hash of functions for copying typed arrays.\n*\n* @private\n* @returns {Object} function hash\n*/\nfunction typedarrays() {\n\tvar out = {\n\t\t'int8array': int8array,\n\t\t'uint8array': uint8array,\n\t\t'uint8clampedarray': uint8clampedarray,\n\t\t'int16array': int16array,\n\t\t'uint16array': uint16array,\n\t\t'int32array': int32array,\n\t\t'uint32array': uint32array,\n\t\t'float32array': float32array,\n\t\t'float64array': float64array\n\t};\n\treturn out;\n}\n\n\n// MAIN //\n\nhash = typedarrays();\n\n\n// EXPORTS //\n\nmodule.exports = hash;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar regexp = require( '@stdlib/utils-regexp-from-string' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar propertyNames = require( '@stdlib/utils-property-names' );\nvar propertyDescriptor = require( '@stdlib/utils-property-descriptor' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar defineProperty = require( '@stdlib/utils-define-property' );\nvar copyBuffer = require( '@stdlib/buffer-from-buffer' );\nvar typedArrays = require( './typed_arrays.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Clones a class instance.\n*\n* ## Notes\n*\n* - This should **only** be used for simple cases. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This approach should be considered **fragile**.\n* - The function is greedy, disregarding the notion of a `level`. Instead, the function deep copies all properties, as we assume the concept of `level` applies only to the class instance reference but not to its internal state. This prevents, in theory, two instances from sharing state.\n*\n*\n* @private\n* @param {Object} val - class instance\n* @returns {Object} new instance\n*/\nfunction cloneInstance( val ) {\n\tvar cache;\n\tvar names;\n\tvar name;\n\tvar refs;\n\tvar desc;\n\tvar tmp;\n\tvar ref;\n\tvar i;\n\n\tcache = [];\n\trefs = [];\n\n\tref = Object.create( getPrototypeOf( val ) );\n\tcache.push( val );\n\trefs.push( ref );\n\n\tnames = propertyNames( val );\n\tfor ( i = 0; i < names.length; i++ ) {\n\t\tname = names[ i ];\n\t\tdesc = propertyDescriptor( val, name );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( val[name] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( val[name], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( ref, name, desc );\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( ref );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( ref );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( ref );\n\t}\n\treturn ref;\n}\n\n/**\n* Copies an error object.\n*\n* @private\n* @param {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error - error to copy\n* @returns {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error copy\n*\n* @example\n* var err1 = new TypeError( 'beep' );\n*\n* var err2 = copyError( err1 );\n* // returns \n*/\nfunction copyError( error ) {\n\tvar cache = [];\n\tvar refs = [];\n\tvar keys;\n\tvar desc;\n\tvar tmp;\n\tvar key;\n\tvar err;\n\tvar i;\n\n\t// Create a new error...\n\terr = new error.constructor( error.message );\n\n\tcache.push( error );\n\trefs.push( err );\n\n\t// If a `stack` property is present, copy it over...\n\tif ( error.stack ) {\n\t\terr.stack = error.stack;\n\t}\n\t// Node.js specific (system errors)...\n\tif ( error.code ) {\n\t\terr.code = error.code;\n\t}\n\tif ( error.errno ) {\n\t\terr.errno = error.errno;\n\t}\n\tif ( error.syscall ) {\n\t\terr.syscall = error.syscall;\n\t}\n\t// Any enumerable properties...\n\tkeys = objectKeys( error );\n\tfor ( i = 0; i < keys.length; i++ ) {\n\t\tkey = keys[ i ];\n\t\tdesc = propertyDescriptor( error, key );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( error[ key ] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( error[ key ], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( err, key, desc );\n\t}\n\treturn err;\n}\n\n\n// MAIN //\n\n/**\n* Recursively performs a deep copy of an input object.\n*\n* @private\n* @param {*} val - value to copy\n* @param {(Array|Object)} copy - copy\n* @param {Array} cache - an array of visited objects\n* @param {Array} refs - an array of object references\n* @param {NonNegativeInteger} level - copy depth\n* @returns {*} deep copy\n*/\nfunction deepCopy( val, copy, cache, refs, level ) {\n\tvar parent;\n\tvar keys;\n\tvar name;\n\tvar desc;\n\tvar ctor;\n\tvar key;\n\tvar ref;\n\tvar x;\n\tvar i;\n\tvar j;\n\n\tlevel -= 1;\n\n\t// Primitives and functions...\n\tif (\n\t\ttypeof val !== 'object' ||\n\t\tval === null\n\t) {\n\t\treturn val;\n\t}\n\tif ( isBuffer( val ) ) {\n\t\treturn copyBuffer( val );\n\t}\n\tif ( isError( val ) ) {\n\t\treturn copyError( val );\n\t}\n\t// Objects...\n\tname = typeOf( val );\n\n\tif ( name === 'date' ) {\n\t\treturn new Date( +val );\n\t}\n\tif ( name === 'regexp' ) {\n\t\treturn regexp( val.toString() );\n\t}\n\tif ( name === 'set' ) {\n\t\treturn new Set( val );\n\t}\n\tif ( name === 'map' ) {\n\t\treturn new Map( val );\n\t}\n\tif (\n\t\tname === 'string' ||\n\t\tname === 'boolean' ||\n\t\tname === 'number'\n\t) {\n\t\t// If provided an `Object`, return an equivalent primitive!\n\t\treturn val.valueOf();\n\t}\n\tctor = typedArrays[ name ];\n\tif ( ctor ) {\n\t\treturn ctor( val );\n\t}\n\t// Class instances...\n\tif (\n\t\tname !== 'array' &&\n\t\tname !== 'object'\n\t) {\n\t\t// Cloning requires ES5 or higher...\n\t\tif ( typeof Object.freeze === 'function' ) {\n\t\t\treturn cloneInstance( val );\n\t\t}\n\t\treturn {};\n\t}\n\t// Arrays and plain objects...\n\tkeys = objectKeys( val );\n\tif ( level > 0 ) {\n\t\tparent = name;\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tx = val[ key ];\n\n\t\t\t// Primitive, Buffer, special class instance...\n\t\t\tname = typeOf( x );\n\t\t\tif (\n\t\t\t\ttypeof x !== 'object' ||\n\t\t\t\tx === null ||\n\t\t\t\t(\n\t\t\t\t\tname !== 'array' &&\n\t\t\t\t\tname !== 'object'\n\t\t\t\t) ||\n\t\t\t\tisBuffer( x )\n\t\t\t) {\n\t\t\t\tif ( parent === 'object' ) {\n\t\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\t\tdesc.value = deepCopy( x );\n\t\t\t\t\t}\n\t\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t\t} else {\n\t\t\t\t\tcopy[ key ] = deepCopy( x );\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Circular reference...\n\t\t\ti = indexOf( cache, x );\n\t\t\tif ( i !== -1 ) {\n\t\t\t\tcopy[ key ] = refs[ i ];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Plain array or object...\n\t\t\tref = ( isArray( x ) ) ? new Array( x.length ) : {};\n\t\t\tcache.push( x );\n\t\t\trefs.push( ref );\n\t\t\tif ( parent === 'array' ) {\n\t\t\t\tcopy[ key ] = deepCopy( x, ref, cache, refs, level );\n\t\t\t} else {\n\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\tdesc.value = deepCopy( x, ref, cache, refs, level );\n\t\t\t\t}\n\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t}\n\t\t}\n\t} else if ( name === 'array' ) {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tcopy[ key ] = val[ key ];\n\t\t}\n\t} else {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\tdefineProperty( copy, key, desc );\n\t\t}\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( copy );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( copy );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( copy );\n\t}\n\treturn copy;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepCopy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar deepCopy = require( './deep_copy.js' );\n\n\n// MAIN //\n\n/**\n* Copies or deep clones a value to an arbitrary depth.\n*\n* @param {*} value - value to copy\n* @param {NonNegativeInteger} [level=+infinity] - copy depth\n* @throws {TypeError} `level` must be a nonnegative integer\n* @returns {*} value copy\n*\n* @example\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\nfunction copy( value, level ) {\n\tvar out;\n\tif ( arguments.length > 1 ) {\n\t\tif ( !isNonNegativeInteger( level ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `level` must be a nonnegative integer. Value: `' + level + '`.' );\n\t\t}\n\t\tif ( level === 0 ) {\n\t\t\treturn value;\n\t\t}\n\t} else {\n\t\tlevel = PINF;\n\t}\n\tout = ( isArray( value ) ) ? new Array( value.length ) : {};\n\treturn deepCopy( value, out, [value], [out], level );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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* Copy or deep clone a value to an arbitrary depth.\n*\n* @module @stdlib/utils-copy\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ {'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\n\n// MODULES //\n\nvar copy = require( './copy.js' );\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an object; e.g., `{}`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an object\n*\n* @example\n* var bool = isObject( {} );\n* // returns true\n*\n* @example\n* var bool = isObject( null );\n* // returns false\n*/\nfunction isObject( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t!isArray( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObject;\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\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar objectPrototype = Object.prototype;\n\n\n// FUNCTIONS //\n\n/**\n* Tests that an object only has own properties.\n*\n* @private\n* @param {Object} obj - value to test\n* @returns {boolean} boolean indicating if an object only has own properties\n*/\nfunction ownProps( obj ) {\n\tvar key;\n\n\t// NOTE: possibility of perf boost if key enumeration order is known (see http://stackoverflow.com/questions/18531624/isplainobject-thing).\n\tfor ( key in obj ) {\n\t\tif ( !hasOwnProp( obj, key ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n\n// MAIN //\n\n/**\n* Tests if a value is a plain object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a plain object\n*\n* @example\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* @example\n* var bool = isPlainObject( null );\n* // returns false\n*/\nfunction isPlainObject( value ) {\n\tvar proto;\n\n\t// Screen for obvious non-objects...\n\tif ( !isObject( value ) ) {\n\t\treturn false;\n\t}\n\t// Objects with no prototype (e.g., `Object.create( null )`) are plain...\n\tproto = getPrototypeOf( value );\n\tif ( !proto ) {\n\t\treturn true;\n\t}\n\t// Objects having a prototype are plain if and only if they are constructed with a global `Object` function and the prototype points to the prototype of a plain object...\n\treturn (\n\t\t// Cannot have own `constructor` property:\n\t\t!hasOwnProp( value, 'constructor' ) &&\n\n\t\t// Prototype `constructor` property must be a function (see also https://bugs.jquery.com/ticket/9897 and http://stackoverflow.com/questions/18531624/isplainobject-thing):\n\t\thasOwnProp( proto, 'constructor' ) &&\n\t\tisFunction( proto.constructor ) &&\n\t\tnativeClass( proto.constructor ) === '[object Function]' &&\n\n\t\t// Test for object-specific method:\n\t\thasOwnProp( proto, 'isPrototypeOf' ) &&\n\t\tisFunction( proto.isPrototypeOf ) &&\n\n\t\t(\n\t\t\t// Test if the prototype matches the global `Object` prototype (same realm):\n\t\t\tproto === objectPrototype ||\n\n\t\t\t// Test that all properties are own properties (cross-realm; *most* likely a plain object):\n\t\t\townProps( value )\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - options to validate\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {(Error|null)} error object or null\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );\n\t}\n\tif ( hasOwnProp( options, 'url' ) ) {\n\t\topts.url = options.url;\n\t\tif ( !isString( opts.url ) ) {\n\t\t\treturn new TypeError( 'invalid option. `url` option must be a string primitive. Option: `' + opts.url + '`.' );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'message' ) ) {\n\t\topts.message = options.message;\n\t\tif ( !isString( opts.message ) ) {\n\t\t\treturn new TypeError( 'invalid option. `message` option must be a string primitive. Option: `' + opts.message + '`.' );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\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* Test if a value is a plain object.\n*\n* @module @stdlib/assert-is-plain-object\n*\n* @example\n* var isPlainObject = require( '@stdlib/assert-is-plain-object' );\n*\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* bool = isPlainObject( null );\n* // returns false\n*/\n\n// MODULES //\n\nvar isPlainObject = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar replace = require( '@stdlib/string-replace' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Returns a function which formats an error message for production.\n*\n* @param {Options} options - function options\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {Function} error formatting function\n*\n* @example\n* var opts = {\n* 'url': 'https://stdlib.io/error-decoder.html'\n* };\n*\n* var fcn = factory( opts );\n* // returns \n*/\nfunction factory( options ) {\n\tvar opts;\n\tvar err;\n\topts = copy( defaults );\n\terr = validate( opts, options );\n\tif ( err ) {\n\t\tthrow err;\n\t}\n\treturn formatProdErrorMessage;\n\n\t/**\n\t* Formats an error message for production.\n\t*\n\t* @private\n\t* @param {string} code - error code\n\t* @param {*} ...args - error message arguments\n\t* @returns {string} formatted error message\n\t*/\n\tfunction formatProdErrorMessage() {\n\t\tvar code = arguments[ 0 ];\n\t\tvar url = opts.url + '?code='+code;\n\t\tvar msg;\n\t\tvar i;\n\t\tfor ( i = 1; i < arguments.length; i++ ) {\n\t\t\turl += '&arg[]=' + encodeURIComponent( arguments[ i ] );\n\t\t}\n\t\tmsg = replace( opts.message, '{{url}}', url );\n\t\tmsg = replace( msg, '{{code}}', code );\n\t\treturn msg;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Format an error message for production.\n*\n* @module @stdlib/error-tools-fmtprodmsg\n*\n* @example\n* var formatProdErrorMessage = require( '@stdlib/error-tools-fmtprodmsg' );\n*\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar formatProdErrorMessage = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( formatProdErrorMessage, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @name formatProdErrorMessage\n* @type {Function}\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\nvar formatProdErrorMessage = factory( defaults );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["defineProperty","Object","has_define_property_support","err","builtin","objectProtoype","prototype","toStr","toString","defineGetter","__defineGetter__","defineSetter","__defineSetter__","lookupGetter","__lookupGetter__","lookupSetter","__lookupSetter__","polyfill","obj","prop","descriptor","hasValue","hasGet","hasSet","call","TypeError","__proto__","value","Error","get","set","require$$1","require$$2","lib","require$$0","main","configurable","enumerable","writable","primitive","FLG","Symbol","hasSymbols","toStringTag","tostring","native_class","v","has","hasOwnProperty","property","toStrTag","hasOwnProp","isOwn","tag","out","valueOf","String","nativeClass","test","object","isPrimitive","isObject","setReadOnly","isString","require$$3","RE_CHARS","str","s","i","length","replace","substring","re","Boolean","isBoolean","codegen","Function","self_1","self","window_1","window","global","module","exports","getThis","Self","Win","Global","arguments","root","nodeList","document","childNodes","typedarray","Int8Array","RE","check_1","reFunctionName","Array","isArray","isObjectLike","predicate","len","arrayfun","_isBuffer","constructor","isBuffer","REGEXP","match","name","ctor","slice","exec","ctorName","typeOf","type","toLowerCase","RegExp","rescape","isFunction","isRegExp","search","newval","Number","isNumber","POSITIVE_INFINITY","NEGATIVE_INFINITY","floor","Math","x","PINF","NINF","isInt","integer","isInteger","isNonNegativeInteger","getProto","getPrototypeOf","proto","reRegExp","isNan","isnan","isCollection","index_of","arr","searchElement","fromIndex","keys","has_arguments_bug","has_builtin","bool","isArguments","bool$8","detect","detect_1","native","propertyIsEnumerable","bool$7","isEnum","hasStringEnumBug","isEnumerableProperty","require$$4","builtin_wrapper","has_enumerable_prototype_bug","has_non_enumerable_properties_bug","is_constructor_prototype","w","indexOf","isConstructorPrototype","EXCLUDED_KEYS","win","bool$4","k","check","hasAutomationEqualityBug","HAS_WINDOW","HAS_ENUM_PROTO_BUG","HAS_NON_ENUM_PROPS_BUG","error","NON_ENUMERABLE","wrapper","skipConstructor","skipPrototype","isFcn","p","push","getOwnPropertyNames","propertyNames","getOwnPropertyDescriptor","propertyDescriptor","desc","Buffer","GlobalBuffer","b","from","buffer","hasInt8Array","isInt8Array","GlobalInt8Array","INT8_MAX","hasUint8Array","Uint8Array","isUint8Array","GlobalUint8Array","UINT8_MAX","hasUint8ClampedArray","Uint8ClampedArray","isUint8ClampedArray","GlobalUint8ClampedArray","hasInt16Array","Int16Array","isInt16Array","GlobalInt16Array","INT16_MAX","hasUint16Array","Uint16Array","isUint16Array","GlobalUint16Array","UINT16_MAX","hasInt32Array","Int32Array","isInt32Array","GlobalInt32Array","INT32_MAX","hasUint32Array","Uint32Array","isUint32Array","GlobalUint32Array","UINT32_MAX","hasFloat32Array","Float32Array","isFloat32Array","GlobalFloat32Array","hasFloat64Array","Float64Array","isFloat64Array","GlobalFloat64Array","NaN","require$$5","require$$6","require$$7","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","isError","regexp","objectKeys","require$$8","require$$9","require$$10","require$$11","copyBuffer","require$$12","typedArrays","deepCopy","val","copy","cache","refs","level","parent","key","ref","j","tmp","message","stack","code","errno","syscall","copyError","Date","Set","Map","freeze","names","create","isExtensible","preventExtensions","isSealed","seal","isFrozen","cloneInstance","copy_1","objectPrototype","isPrototypeOf","ownProps","validate","opts","options","url","defaults","factory_1","msg","encodeURIComponent","formatProdErrorMessage","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","RangeError","format"],"mappings":";6kBAsBA,ICAIA,EDA0C,mBAA1BC,OAAOD,eAAkCC,OAAOD,eAAiB,KC4BrF,IAAAE,EAbA,WAEC,IAEC,OADAF,EAAgB,GAAI,IAAK,KAClB,EACN,MAAQG,GACT,OAAO,ICiBTC,EALqBH,OAAOD,eC/BxBK,EAAiBJ,OAAOK,UACxBC,EAAQF,EAAeG,SACvBC,EAAeJ,EAAeK,iBAC9BC,EAAeN,EAAeO,iBAC9BC,EAAeR,EAAeS,iBAC9BC,EAAeV,EAAeW,iBAuFlC,IAAAC,EAnDA,SAAyBC,EAAKC,EAAMC,GACnC,IAAId,EACAe,EACAC,EACAC,EAEJ,GAAoB,iBAARL,GAA4B,OAARA,GAAsC,mBAAtBX,EAAMiB,KAAMN,GAC3D,MAAM,IAAIO,UAAW,+DAAiEP,EAAM,MAE7F,GAA2B,iBAAfE,GAA0C,OAAfA,GAAoD,mBAA7Bb,EAAMiB,KAAMJ,GACzE,MAAM,IAAIK,UAAW,oEAAsEL,EAAa,MAyBzG,IAvBAC,EAAa,UAAWD,KAGtBP,EAAaW,KAAMN,EAAKC,IACxBJ,EAAaS,KAAMN,EAAKC,IAGxBb,EAAYY,EAAIQ,UAChBR,EAAIQ,UAAYrB,SAGTa,EAAKC,GACZD,EAAKC,GAASC,EAAWO,MAGzBT,EAAIQ,UAAYpB,GAEhBY,EAAKC,GAASC,EAAWO,OAG3BL,EAAW,QAASF,EACpBG,EAAW,QAASH,EAEfC,IAAcC,GAAUC,GAC5B,MAAM,IAAIK,MAAO,wHASlB,OANKN,GAAUb,GACdA,EAAae,KAAMN,EAAKC,EAAMC,EAAWS,KAErCN,GAAUZ,GACdA,EAAaa,KAAMN,EAAKC,EAAMC,EAAWU,KAEnCZ,GCrEJd,EAAU2B,EACVd,EAAWe,EAefC,EAjB+BC,IASb9B,EAEAa,EC7BdjB,EAAiBkC,EAmCrB,IAAAC,EAZA,SAAmCjB,EAAKC,EAAMQ,GAC7C3B,EAAgBkB,EAAKC,EAAM,CAC1BiB,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,KCJXM,EAL+BC,ECA/B,IAAAK,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCMjB,ICdIa,EDIJ,WACC,MACmB,mBAAXC,QACoB,iBAApBA,OAAQ,OCPPC,GAqBV,ICTAT,EDEA,WACC,OAASO,GAAqC,iBAAvBC,OAAOE,aEf/BC,EALY3C,OAAOK,UAAUE,SCAzBD,EAAQ2B,EAiCZ,IAAAW,EAPA,SAAsBC,GACrB,OAAOvC,EAAMiB,KAAMsB,IC3BhBC,EAAM9C,OAAOK,UAAU0C,eAyC3B,ICjBAf,EDIA,SAAqBN,EAAOsB,GAC3B,OACCtB,SAKMoB,EAAIvB,KAAMG,EAAOsB,IEnCrBC,EAA+B,mBAAXT,OAA0BA,OAAOE,YAAc,GCAnEQ,EAAajB,EACbS,EDIaO,ECHb3C,EAAQyB,EAwDZ,ICpCI5B,EAAU2B,EACVd,EDKJ,SAAsB6B,GACrB,IAAIM,EACAC,EACAC,EAEJ,GAAKR,QACJ,OAAOvC,EAAMiB,KAAMsB,GAEpBO,EAAMP,EAAGH,GACTS,EAAQD,EAAYL,EAAGH,GAGvB,IACCG,EAAGH,QAAgB,EAClB,MAAQxC,GACT,OAAOI,EAAMiB,KAAMsB,GASpB,OAPAQ,EAAM/C,EAAMiB,KAAMsB,GAEbM,EACJN,EAAGH,GAAgBU,SAEZP,EAAGH,GAEJW,GCdRrB,EAjBqBC,IASNjB,EAEAb,EChCXmD,ECDUC,OAAOlD,UAAUiD,QDyB/B,IEvBIE,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADA4B,EAAQ/B,KAAMG,IACP,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB6B,SAGjBhB,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,EAAW9B,EA0Bf,ICSI+B,EAAc5B,EACd6B,EDjBJ,SAAmBpC,GAClB,OAASiC,EAAajC,IAAWkC,EAAUlC,ICkBxCkC,EAAWG,EAKfF,EAAaC,EAAU,cANL/B,GAOlB8B,EAAaC,EAAU,WAAYF,GAKnC,IAAA5B,EAAiB8B,EClDbA,EAAW7B,EAAsC0B,YAKjDK,EAAW,yBAqDf,ICzCAhC,EDIA,SAAkBiC,GACjB,IACIC,EACAC,EAEJ,IAAML,EAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAGrG,GAAkB,MAAbA,EAAK,GAGT,IAAME,EADAF,EAAIG,OACI,EAAGD,GAAK,GACH,MAAbF,EAAKE,GADcA,KAO1B,YAAW,IAANA,GAAgBA,GAAK,EAClBF,EAAII,QAASL,EAAU,SAM/BE,GAHAA,EAAID,EAAIK,UAAW,EAAGH,IAGhBE,QAASL,EAAU,QAGzBC,EAAMA,EAAK,GAAMC,EAAID,EAAIK,UAAWH,KE/CrCI,EALS,ICyBT,IAAAjC,EAPA,SAAoBZ,GACnB,MAA0B,kBAAVA,GCjBbnB,ECDWiE,QAAQnE,UAAUE,SDyBjC,IEvBIiD,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADAnB,EAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAoBhC,GACnB,MAAsB,iBAAVA,IACNA,aAAiB8C,UAGjBjC,EACGkB,EAAM/B,GAEoB,qBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,GAAW9B,EAkCf,ICAI+B,GAAc5B,EACdwC,GDRJ,SAAoB/C,GACnB,OAASiC,EAAajC,IAAWkC,GAAUlC,ICSxCkC,GAAWG,EAKfF,GAAaY,GAAW,cANN1C,GAOlB8B,GAAaY,GAAW,WAAYb,IAKpC,IAAA5B,GAAiByC,GCpCjB,IAAAC,GAPA,WACC,OAAO,IAAIC,SAAU,eAAd,ICFRC,GAL4B,iBAATC,KAAsBA,KAAO,KCKhDC,GAL8B,iBAAXC,OAAwBA,OAAS,6GCAhD9D,GAA0B,iBAAX+D,GAAwBA,GAAS,KAKpDC,OAAOC,QAAUjE,OCLbwD,GAAYxC,GAAuC0B,YACnDwB,GAAUrD,GACVsD,GAAOrD,GACPsD,GAAMtB,GACNuB,sCAkDJ,IAAApD,GA7BA,SAAoBwC,GACnB,GAAKa,UAAUnB,OAAS,CACvB,IAAMK,GAAWC,GAChB,MAAM,IAAIlD,UAAW,+DAA+DkD,EAAQ,MAE7F,GAAKA,EACJ,OAAOS,KAKT,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,MAAM,IAAI3D,MAAO,uDC3Cd6D,GCOYvD,KDNZwD,GAAWD,GAAKE,UAAYF,GAAKE,SAASC,WER1CC,GAAaC,UCEbC,GAAK7D,EACLwD,GHUaA,GGTbG,GDCaA,GC6BjB,IAAAG,GAnBA,WACC,MAEe,mBAAPD,IAGe,iBAAfF,IAGa,mBAAbH,ICST,IAAAvD,GAPA,WACC,MAAO,2BCEJ8D,GAAiBlE,GADHG,EAOL+D,GAAgB,SCjCR/D,MDsCrB,IAAAD,GAAiBgE,GEtCbxC,GAAcvB,EAwClB,ICpBAD,GDWKiE,MAAMC,QACND,MAAMC,QARX,SAAkBxE,GACjB,MAAkC,mBAAzB8B,GAAa9B,IEzBnBwE,GAAUjE,GC0Bd,ICGIkE,GDbJ,SAAuBzE,GACtB,OACW,OAAVA,GACiB,iBAAVA,GCQSO,EAOLkE,GAAc,oBFR3B,SAAmBC,GAClB,GAA0B,mBAAdA,EACX,MAAM,IAAI5E,UAAW,sDAAwD4E,EAAY,MAE1F,OASA,SAAgB1E,GACf,IAAI2E,EACAlC,EACJ,IAAM+B,GAASxE,GACd,OAAO,EAGR,GAAa,KADb2E,EAAM3E,EAAM0C,QAEX,OAAO,EAER,IAAMD,EAAI,EAAGA,EAAIkC,EAAKlC,IACrB,IAAiC,IAA5BiC,EAAW1E,EAAOyC,IACtB,OAAO,EAGT,OAAO,GEpBuCmC,CAAUH,KAK1D,IAAAnE,GAAiBmE,GCvCbA,GAAelE,GA+CnB,IC3BAD,GDOA,SAAmBN,GAClB,OACCyE,GAAczE,KAGbA,EAAM6E,WAEL7E,EAAM8E,aAGgC,mBAA/B9E,EAAM8E,YAAYC,UACzB/E,EAAM8E,YAAYC,SAAU/E,KEtC5B8B,GAAcvB,EACd6D,GAAKhE,GAA0C4E,OAC/CD,GAAW1E,GAuDf,IAAAG,GAxBA,SAA0BW,GACzB,IAAI8D,EACAC,EACAC,EAEJ,IAAe,YADfD,EAAOpD,GAAaX,GAAIiE,MAAO,GAAI,KACC,UAATF,IAAqB/D,EAAE2D,YAAc,CAE/D,GAA0B,iBAD1BK,EAAOhE,EAAE2D,aACQI,KAChB,OAAOC,EAAKD,KAGb,GADAD,EAAQb,GAAGiB,KAAMF,EAAKtG,YAErB,OAAOoG,EAAO,GAGhB,OAAKF,GAAU5D,GACP,SAED+D,GCnDJI,GCkBkB/E,GDmCtB,IErDI+E,GDkBkB/E,GCAtB,ICFIgF,GHkBJ,SAAiBpE,GAChB,IAAIqE,EAGJ,OAAW,OAANrE,EACG,OAKM,YAHdqE,SAAcrE,GAINmE,GAAUnE,GAAIsE,cAEfD,GG9BJlG,GDNJ,SAAiB6B,GAChB,OAAOmE,GAAUnE,GAAIsE,eCetBnF,GAZkBC,KAOajB,GAAWiG,GCtBtCA,GAAShF,GA2Bb,ICNAD,GDFA,SAAqBN,GAEpB,MAA6B,aAApBuF,GAAQvF,IErBdqF,GCFOK,OAAO/G,UAAU0G,KD0B5B,IEvBIvD,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADAqF,GAAKxF,KAAMG,IACJ,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBN,IA0CrB,IC1CIoF,GAAUpF,EACVqF,GAAaxF,GACbgC,GAAW/B,EAAsC4B,YACjD4D,GDuBJ,SAAmB7F,GAClB,MAAsB,iBAAVA,IACNA,aAAiB0F,SAGjB7E,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MC2BxB,ICvCAM,GDmBA,SAAkBiC,EAAKuD,EAAQC,GAC9B,IAAM3D,GAAUG,GACf,MAAM,IAAIzC,UAAW,wEAA0EyC,EAAM,MAEtG,GAAKH,GAAU0D,GACdA,EAASH,GAASG,GAClBA,EAAS,IAAIJ,OAAQI,EAAQ,UAEzB,IAAMD,GAAUC,GACpB,MAAM,IAAIhG,UAAW,+FAAiGgG,EAAS,MAEhI,IAAM1D,GAAU2D,KAAaH,GAAYG,GACxC,MAAM,IAAIjG,UAAW,gGAAkGiG,EAAS,MAEjI,OAAOxD,EAAII,QAASmD,EAAQC,IEhC7B,IAAAnF,GAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCAjBM,GCjBiB0F,OCAbnH,GCAS0B,GAMS5B,UAAUE,SDkBhC,IEvBIiD,GAAc1B,EACd4F,GAAS3F,GACT0B,GFSJ,SAAe/B,GACd,IAEC,OADAnB,GAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IETLqC,GARiBN,IA2CrB,IAAAyB,GAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiBgG,KAGjBnF,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MCnCpBiC,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd0F,GDfJ,SAAmBjG,GAClB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa8D,GAAU,cANL5F,IAOlB8B,GAAa8D,GAAU,WAAY/D,IAKnC,IAAA5B,GAAiB2F,GCvBjB3F,GALmB0F,OAAOE,kBCS1B5F,GA1BaC,GAqBa4F,kBChCtBC,GCsBQC,KAAKD,MDIjB,IENA9F,GFDA,SAAoBgG,GACnB,OAAQF,GAAME,KAAOA,GGpBlBC,GAAOhG,GACPiG,GAAOpG,GACPqG,GAAQpG,GAuBZ,IAAAqG,GAXA,SAAoB1G,GACnB,OACCA,EAAQuG,IACRvG,EAAQwG,IACRC,GAAOzG,IClBLiG,GAAW1F,GAAsC0B,YACjDwE,GAAQrG,GA6BZ,IAAAQ,GAVA,SAAoBZ,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,ICvBLiG,GAAW1F,GAAsC2B,SACjDuE,GAAQrG,GA6BZ,IAAA4B,GAVA,SAAoBhC,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICMI+B,GAAc5B,EACdoG,GDdJ,SAAoB3G,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICexCkC,GAAWG,GAKfF,GAAawE,GAAW,cANNtG,IAOlB8B,GAAawE,GAAW,WAAYzE,IAKpC,IAAA5B,GAAiBqG,GCvDbA,GAAYpG,GAAuC0B,YA6BvD,IAAArB,GAVA,SAA+BZ,GAC9B,OACC2G,GAAW3G,IACXA,GAAS,GCtBP2G,GAAYpG,GAAuC2B,SA6BvD,IAAAF,GAVA,SAA+BhC,GAC9B,OACC2G,GAAW3G,IACXA,EAAM4B,WAAa,GCtBjBK,GAAc1B,GACd2B,GAAW9B,GAsCf,ICGI+B,GAAc5B,EACdqG,GDXJ,SAA+B5G,GAC9B,OAASiC,GAAajC,IAAWkC,GAAUlC,ICYxCkC,GAAWG,GAKfF,GAAayE,GAAsB,cANjBvG,IAOlB8B,GAAayE,GAAsB,WAAY1E,IAK/C,IAAA5B,GAAiBsG,GCxDbC,GAAWvI,OAAOwI,eCatB,IAAAC,GARA,SAAmBxH,GAElB,OAAOA,EAAIQ,WCPR+B,GAAcvB,EACdsG,GAAWzG,GA+Bf,IAAAd,GAnBA,SAAyBC,GACxB,IAAIwH,EAAQF,GAAUtH,GACtB,OAAKwH,GAAmB,OAAVA,EACNA,EAEgC,sBAAnCjF,GAAavC,EAAIuF,aAEdvF,EAAIuF,YAAYnG,UAEnBY,aAAejB,OACZA,OAAOK,UAGR,MCzBJF,GHIaoI,GGHbvH,GAAWe,GCFXwG,GDAatG,GAQAjC,OAAOwI,gBACZrI,GAEAa,GCoBZ,ICdAgB,GDFA,SAAyBN,GACxB,OACCA,QAGO,MAGRA,EAAQ1B,OAAQ0B,GAET6G,GAAU7G,KEzBd8G,GAAiBvG,GACjBuB,GAAc1B,EAwClB,ICrBAE,GDAA,SAAkBN,GACjB,GAAsB,iBAAVA,GAAgC,OAAVA,EACjC,OAAO,EAGR,GAAKA,aAAiBC,MACrB,OAAO,EAGR,KAAQD,GAAQ,CACf,GAA8B,mBAAzB8B,GAAa9B,GACjB,OAAO,EAERA,EAAQ8G,GAAgB9G,GAEzB,OAAO,GEdR,IAAAQ,GAPA,WACC,MAAO,oCCWJwG,GAAW5G,GADGG,EAOLyG,GAAU,SChCRzG,UCAX6B,GAAW7B,EAAsC0B,YACjD+E,GFyCaA,GEXjB,ICdA1G,GDAA,SAAuBiC,GACtB,IAAMH,GAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAMrG,OAHAA,EAAMyE,KAAW3B,KAAM9C,IAGN,IAAImD,OAAQnD,EAAI,GAAIA,EAAI,IAAO,MEJjD,IAAA/B,GAPA,SAAgB8F,GACf,OAASA,GAAMA,GCfZL,GAAW1F,GAAsC0B,YACjDgF,GCcQ1G,GDmBZ,IAAAK,GAVA,SAAgBZ,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,IE3BLiG,GAAW1F,GAAsC2B,SACjD+E,GDcQ1G,GCeZ,IAAAyB,GAVA,SAAgBhC,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd2G,GDfJ,SAAgBlH,GACf,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa+E,GAAO,cANF7G,IAOlB8B,GAAa+E,GAAO,WAAYhF,IAKhC,IAAA5B,GAAiB4G,GCxDbP,GAAYpG,GAkChB,IClCI2G,GAAQ3G,GACR4G,GDmBJ,SAAuBnH,GACtB,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QENqB,kBDnBzBN,GAAW/B,EAAsC4B,YACjD0E,GAAYtE,GAAuCJ,YA0GvD,IAAAmF,GAhDA,SAAkBC,EAAKC,EAAeC,GACrC,IAAI5C,EACAlC,EACJ,IAAM0E,GAAcE,KAAUjF,GAAUiF,GACvC,MAAM,IAAIvH,UAAW,0EAA4EuH,EAAM,MAGxG,GAAa,KADb1C,EAAM0C,EAAI3E,QAET,OAAQ,EAET,GAA0B,IAArBmB,UAAUnB,OAAe,CAC7B,IAAMiE,GAAWY,GAChB,MAAM,IAAIzH,UAAW,6DAA+DyH,EAAY,MAEjG,GAAKA,GAAa,EAAI,CACrB,GAAKA,GAAa5C,EACjB,OAAQ,EAETlC,EAAI8E,OAEJ9E,EAAIkC,EAAM4C,GACD,IACR9E,EAAI,QAINA,EAAI,EAGL,GAAKyE,GAAOI,IACX,KAAQ7E,EAAIkC,EAAKlC,IAChB,GAAKyE,GAAOG,EAAI5E,IACf,OAAOA,OAIT,KAAQA,EAAIkC,EAAKlC,IAChB,GAAK4E,EAAK5E,KAAQ6E,EACjB,OAAO7E,EAIV,OAAQ,GErDTnC,GALcC,GClBd,IAAA9B,GAPA,SAAeuB,GACd,OAAO1B,OAAOkJ,KAAMlJ,OAAQ0B,KCrBzBwH,GAAOjH,GAmCX,IAAAkH,GAPA,WACC,OAlBD,WACC,OAA8C,KAArCD,GAAM3D,YAAe,IAAKnB,OAiB5BX,CAAM,EAAG,ICxBjB2F,QALoC,IAAhBpJ,OAAOkJ,KCAvB1F,GAAcvB,EA+BlB,IC1BIoH,GD0BJnH,GAPA,SAAsBR,GACrB,MAAkC,uBAAzB8B,GAAa9B,ICzBnB4H,GAAcrH,GA2BdsH,GAPJ,WACC,OAAOD,GAAa/D,WAMdiE,GAKP,IC3BIH,GD2BJI,GAAiBJ,GEDjBK,GAL2B1J,OAAOK,UAAUsJ,qBDHxCC,IAvBS3H,GAiBGV,KAAM,OAAQ,KAW9B,IE5BIuC,GAAW7B,EACX2G,GAAQ9G,GAAmC6B,YAC3C0E,GAAYtG,GAAuC4B,YACnDkG,GAAS9F,GACT+F,GFwBaT,GE6BjB,IAAAnH,GAzBA,SAA+BR,EAAOsB,GACrC,IAAIqG,EACJ,OACC3H,YAKD2H,EAAOQ,GAAOtI,KAAMG,EAAOsB,KACb8G,IAAoBhG,GAAUpC,IAIzCkH,GAFF5F,GAAYA,IAGXqF,GAAWrF,IACXA,GAAY,GACZA,EAAWtB,EAAM0C,OAGZiF,IC3BRrH,GAL2BC,GCnBvBiB,GAAajB,EACb8H,GAAuBjI,GACvBoE,GAAUnE,GACVsG,GAAYtE,GCiChB,IAAA/B,GAjBwBC,GACbH,GDQX,SAAsBJ,GACrB,OACW,OAAVA,GACiB,iBAAVA,IACNwE,GAASxE,IACc,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QAhCS4F,YAiCf9G,GAAYxB,EAAO,YAClBqI,GAAsBrI,EAAO,WEtC5B4H,GAAcrH,GACd9B,GAAU2B,GAKVgF,GAAQb,MAAM5F,UAAUyG,MA+B5B,IAAAmD,GAVA,SAAevI,GACd,OAAK4H,GAAa5H,GACVvB,GAAS2G,GAAMvF,KAAMG,IAEtBvB,GAASuB,ICnBjB,ICAAwI,GAZ2BjI,IDK3B,cCEuC,aCWvCkI,IAlB2BlI,GAKjB,CACT1B,SAAY,MAO0B,YCCvC,ICJI8I,GDIJe,GAPA,SAAiC1I,GAChC,OAASA,EAAM8E,aAAe9E,EAAM8E,YAAYnG,YAAcqB,GER3D2I,GAAwB,oBAAXtF,YAA2B,EAASA,ODAjD7B,GAAajB,EACbqI,GAAUxI,GACVmF,GAASlF,GACTwI,GAAyBxG,GACzByG,wPACAC,GCAaJ,GD2CbK,GAzBJ,WACC,IAAIC,EACJ,GAAuB,cAAlB1D,GAAQwD,IACZ,OAAO,EAER,IAAME,KAAKF,GACV,KAEmC,IAAjCH,GAASE,GAAeG,IACxBzH,GAAYuH,GAAKE,IACJ,OAAbF,GAAKE,IACkB,WAAvB1D,GAAQwD,GAAKE,KAEbJ,GAAwBE,GAAKE,IAE7B,MAAQzK,GACT,OAAO,EAGT,OAAO,EAMD0K,GAKP,IErDIvB,GAA2B,oBAAXtE,OCAhB8F,GHqDaxB,GGpDbkB,GAAyBzI,GACzBgJ,GDGazB,GCuBjB,IC5BIlD,GAAelE,GACfiB,GAAapB,EACbwH,GAAcvH,GACdgJ,GAAqBhH,GACrBiH,GAAyBhB,GACzBO,GDSJ,SAAkB7I,GACjB,IAAoB,IAAfoJ,KAAyBD,GAC7B,OAAON,GAAwB7I,GAEhC,IACC,OAAO6I,GAAwB7I,GAC9B,MAAQuJ,GACT,OAAO,ICfLC,iHAyEJ,IC7EI/K,GAAU4B,GACVoJ,GAAUpH,GACV/C,GDuBJ,SAAeU,GACd,IAAI0J,EACAC,EACAC,EACAjI,EACAsH,EACAY,EACApH,EAGJ,GADAd,EAAM,GACDiG,GAAa5H,GAAU,CAE3B,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,YAGb,OAAO8C,EAER,GAAsB,iBAAV3B,GAEX,GAAKA,EAAM0C,OAAS,IAAMlB,GAAYxB,EAAO,KAC5C,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,gBAGR,CAEN,IAAe,KADf+K,EAA2B,mBAAV5J,KACQyE,GAAczE,GACtC,OAAO2B,EAERgI,EAAkBN,IAAsBO,EAEzC,IAAMX,KAAKjJ,EACF2J,GAAuB,cAANV,IAAuBzH,GAAYxB,EAAOiJ,IAClEtH,EAAImI,KAAMjI,OAAQoH,IAGpB,GAAKK,GAEJ,IADAI,EAAkBb,GAAwB7I,GACpCyC,EAAI,EAAGA,EAAI+G,GAAe9G,OAAQD,IACvCoH,EAAIL,GAAgB/G,GACZiH,GAAyB,gBAANG,IAAyBrI,GAAYxB,EAAO6J,IACtElI,EAAImI,KAAMjI,OAAQgI,IAIrB,OAAOlI,GEnDRrB,GDrBkBF,GADIG,KA6BbkJ,GAEAhL,GAGDa,GE7BRoI,QALmD,IAA/BpJ,OAAOyL,oBCAvBC,GAAgB1L,OAAOyL,oBAgC3B,IChCIvC,GAAOjH,GCgCX,IAAAD,GAjBkBC,GFUlB,SAA8BP,GAC7B,OAAOgK,GAAe1L,OAAQ0B,KCA/B,SAA8BA,GAC7B,OAAOwH,GAAMlJ,OAAQ0B,KEtBtB0H,QALwD,IAApCpJ,OAAO2L,yBCAvBC,GAAqB5L,OAAO2L,yBAuChC,ICvCIzI,GAAajB,ECkCjB,IAAAD,GAjBkBC,GFUlB,SAAmCP,EAAOsB,GACzC,IAAI6I,EACJ,OAAKnK,cAIa,KADlBmK,EAAOD,GAAoBlK,EAAOsB,IAF1B,KAG4B6I,GCLrC,SAAmCnK,EAAOsB,GACzC,OAAKE,GAAYxB,EAAOsB,GAChB,CACNb,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,EAAOsB,IAGX,o4qBErCJd,GAA0C4J,GAK9C7G,OAAOC,QAAUhD,OCLbuE,GAAWxE,GACX8J,sCA4CJ,IAAA7J,GA9BA,WACC,IAAImH,EACA2C,EAEJ,GAA6B,mBAAjBD,GACX,OAAO,EAGR,IAEEC,EADiC,mBAAtBD,GAAaE,KACpBF,GAAaE,KAAM,CAAE,EAAG,EAAG,EAAG,IAE9B,IAAIF,GAAc,CAAE,EAAG,EAAG,EAAG,IAElC1C,EACC5C,GAAUuF,IACC,IAAXA,EAAG,IACQ,IAAXA,EAAG,IACQ,IAAXA,EAAG,IACQ,IAAXA,EAAG,GAEH,MAAQ9L,GACTmJ,GAAO,EAER,OAAOA,GCtBRrH,GAL2BC,GCE3B,ICDIC,SCb2B4J,ODc3B9K,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GAjB2BC,KASnBC,GAEAlB,GEjBJqI,GANapH,GACJH,GAKiBmK,MCN1BxF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAI,GAVA,SAAqBgK,GACpB,IAAMzF,GAAUyF,GACf,MAAM,IAAI1K,UAAW,oDAAsD0K,EAAS,KAErF,OAAOJ,GAAOG,KAAMC,IC1BjBzF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAd,GAVA,SAAqBkL,GACpB,IAAMzF,GAAUyF,GACf,MAAM,IAAI1K,UAAW,oDAAsD0K,EAAS,KAErF,OAAO,IAAIJ,GAAQI,ICOpBlK,GHtBiBqH,GGMNvH,GACIC,GClBXyB,GAAcvB,EAKdkK,GAAsC,mBAAdtG,UA6B5B,IClCI3D,GAA8B,mBAAd2D,UAA6BA,UAAY,KCAzDuG,GFwBJ,SAAsB1K,GACrB,OACGyK,IAAgBzK,aAAiBmE,WACV,uBAAzBrC,GAAa9B,IExBX2K,GDEanK,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAgC,mBAApBsD,GACX,OAAO,EAGR,IACCtD,EAAM,IAAIsD,GAAiB,CAAE,EAAG,MAAO,KAAMC,MAC7CjD,EACC+C,GAAarD,IACA,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEO,MDDZA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb8B,mBAAd0F,UAA6BA,eAAY,EDczD7E,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB0BC,KFSlB9B,GAEAa,GGvBJwC,GAAcvB,EAKdsK,GAAwC,mBAAfC,WA6B7B,IClCItK,GAA+B,mBAAfsK,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuB/K,GACtB,OACG6K,IAAiB7K,aAAiB8K,YACX,wBAAzBhJ,GAAa9B,IEzBXgL,GDGaxK,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB2D,GACX,OAAO,EAGR,IAEC3D,EAAM,IAAI2D,GADV3D,EAAM,CAAE,EAAG,MAAO,KAAM4D,IAAaA,MAErCtD,EACCoD,GAAc1D,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ4D,MAAb5D,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCb+B,mBAAfqM,WAA8BA,gBAAa,EDc3DxL,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd2K,GAAsD,mBAAtBC,kBA6BpC,IClCI3K,GAAsC,mBAAtB2K,kBAAqCA,kBAAoB,KCAzEC,GFwBJ,SAA8BpL,GAC7B,OACGkL,IAAwBlL,aAAiBmL,mBAClB,+BAAzBrJ,GAAa9B,IE1BXqL,GDIa7K,GCuCjB,IAAAA,GA7BA,WACC,IAAImH,EACAN,EAEJ,GAAwC,mBAA5BgE,GACX,OAAO,EAGR,IACChE,EAAM,IAAIgE,GAAyB,EAAG,EAAG,EAAG,EAAG,KAAM,KAAM,IAAK,MAChE1D,EACCyD,GAAqB/D,IACR,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,MAAbA,EAAK,IACQ,MAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbsC,mBAAtB0M,kBAAqCA,uBAAoB,EDczE7L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjBkCC,KFS1B9B,GAEAa,GGvBJwC,GAAcvB,EAKd+K,GAAwC,mBAAfC,WA6B7B,IClCI/K,GAA+B,mBAAf+K,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBxL,GACtB,OACGsL,IAAiBtL,aAAiBuL,YACX,wBAAzBzJ,GAAa9B,IExBXyL,GDEajL,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArBoE,GACX,OAAO,EAGR,IACCpE,EAAM,IAAIoE,GAAkB,CAAE,EAAG,MAAO,KAAMC,QAC9C/D,EACC6D,GAAcnE,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,QDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAf8M,WAA8BA,gBAAa,EDc3DjM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdoL,GAA0C,mBAAhBC,YA6B9B,IClCIpL,GAAgC,mBAAhBoL,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwB7L,GACvB,OACG2L,IAAkB3L,aAAiB4L,aACZ,yBAAzB9J,GAAa9B,IEzBX8L,GDGatL,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtByE,GACX,OAAO,EAGR,IAECzE,EAAM,IAAIyE,GADVzE,EAAM,CAAE,EAAG,MAAO,KAAM0E,MAAcA,QAEtCpE,EACCkE,GAAexE,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ0E,QAAb1E,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhBmN,YAA+BA,iBAAc,EDc7DtM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdyL,GAAwC,mBAAfC,WA6B7B,IClCIzL,GAA+B,mBAAfyL,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBlM,GACtB,OACGgM,IAAiBhM,aAAiBiM,YACX,wBAAzBnK,GAAa9B,IExBXmM,GDEa3L,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB8E,GACX,OAAO,EAGR,IACC9E,EAAM,IAAI8E,GAAkB,CAAE,EAAG,MAAO,KAAMC,aAC9CzE,EACCuE,GAAc7E,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,aDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAfwN,WAA8BA,gBAAa,EDc3D3M,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd8L,GAA0C,mBAAhBC,YA6B9B,IClCI9L,GAAgC,mBAAhB8L,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwBvM,GACvB,OACGqM,IAAkBrM,aAAiBsM,aACZ,yBAAzBxK,GAAa9B,IEzBXwM,GDGahM,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBmF,GACX,OAAO,EAGR,IAECnF,EAAM,IAAImF,GADVnF,EAAM,CAAE,EAAG,MAAO,KAAMoF,WAAcA,aAEtC9E,EACC4E,GAAelF,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQoF,aAAbpF,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhB6N,YAA+BA,iBAAc,EDc7DhN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdmM,GAA4C,mBAAjBC,aA6B/B,IClCInM,GAAiC,mBAAjBmM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB5M,GACxB,OACG0M,IAAmB1M,aAAiB2M,cACb,0BAAzB7K,GAAa9B,IE1BXuG,GAAOnG,GACPyM,GDGarM,GCqCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvBwF,GACX,OAAO,EAGR,IACCxF,EAAM,IAAIwF,GAAoB,CAAE,EAAK,MAAO,KAAM,OAClDlF,EACCiF,GAAgBvF,IACH,IAAbA,EAAK,IACQ,oBAAbA,EAAK,KACS,oBAAdA,EAAK,IACLA,EAAK,KAAQd,GAEb,MAAQ/H,GACTmJ,GAAO,EAER,OAAOA,GCtBR,ICDIlJ,GCbiC,mBAAjBkO,aAAgCA,kBAAe,EDc/DrN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB6BC,KFSrB9B,GAEAa,GGvBJwC,GAAcvB,EAKduM,GAA4C,mBAAjBC,aA6B/B,IClCIvM,GAAiC,mBAAjBuM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyBhN,GACxB,OACG8M,IAAmB9M,aAAiB+M,cACb,0BAAzBjL,GAAa9B,IE1BXiN,GDIazM,GCoCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvB4F,GACX,OAAO,EAGR,IACC5F,EAAM,IAAI4F,GAAoB,CAAE,EAAK,MAAO,KAAMC,MAClDvF,EACCqF,GAAgB3F,IACH,IAAbA,EAAK,IACQ,OAAbA,EAAK,KACS,OAAdA,EAAK,IACLA,EAAK,IAAQA,EAAK,GAElB,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCrBR,ICKIxC,GANA1G,GCbiC,mBAAjBsO,aAAgCA,kBAAe,EDc/DzN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCajBkF,GET4B5E,KFSrB9B,GAEAa,GAMR,IG7BI6E,GAAY5D,GACZuK,GAAa1K,GACb+K,GAAoB9K,GACpBkL,GAAalJ,GACbuJ,GAActD,GACd2D,GAAakB,GACbb,GAAcc,GACdT,GAAeU,GACfN,GHqBa5H,GGJjB,SAASmI,GAAWjG,GACnB,OAAO,IAAIlD,GAAWkD,GAUvB,SAASkG,GAAYlG,GACpB,OAAO,IAAIyD,GAAYzD,GAUxB,SAASmG,GAAmBnG,GAC3B,OAAO,IAAI8D,GAAmB9D,GAU/B,SAASoG,GAAYpG,GACpB,OAAO,IAAIkE,GAAYlE,GAUxB,SAASqG,GAAarG,GACrB,OAAO,IAAIuE,GAAavE,GAUzB,SAASsG,GAAYtG,GACpB,OAAO,IAAI4E,GAAY5E,GAUxB,SAASuG,GAAavG,GACrB,OAAO,IAAIiF,GAAajF,GAUzB,SAASwG,GAAcxG,GACtB,OAAO,IAAIsF,GAActF,GAU1B,SAASyG,GAAczG,GACtB,OAAO,IAAI0F,GAAc1F,GAgC1B,IClJI7F,GAAajB,EACbiE,GAAUpE,GACV2E,GAAW1E,GACX0N,GAAU1L,GACVkD,GAAS+C,GACT0F,GAASb,GACTvE,GAAUwE,GACVa,GAAaZ,GACbrD,GAAgBkE,GAChBhE,GAAqBiE,GACrBrH,GAAiBsH,GACjB/P,GAAiBgQ,EACjBC,GAAaC,GACbC,GD+GO,CACTlB,UAAaA,GACbC,WAAcA,GACdC,kBAAqBA,GACrBC,WAAcA,GACdC,YAAeA,GACfC,WAAcA,GACdC,YAAeA,GACfC,aAAgBA,GAChBC,aAAgBA,ICQlB,SAASW,GAAUC,EAAKC,EAAMC,EAAOC,EAAMC,GAC1C,IAAIC,EACAvH,EACAtC,EACAiF,EACAhF,EACA6J,EACAC,EACA3I,EACA7D,EACAyM,EAKJ,GAHAJ,GAAS,EAIO,iBAARJ,GACC,OAARA,EAEA,OAAOA,EAER,GAAK3J,GAAU2J,GACd,OAAOJ,GAAYI,GAEpB,GAAKX,GAASW,GACb,OAnFF,SAAoBnF,GACnB,IAEI/B,EACA2C,EACAgF,EACAH,EACAxQ,EACAiE,EAPAmM,EAAQ,GACRC,EAAO,GA8BX,IArBArQ,EAAM,IAAI+K,EAAMzE,YAAayE,EAAM6F,SAEnCR,EAAM9E,KAAMP,GACZsF,EAAK/E,KAAMtL,GAGN+K,EAAM8F,QACV7Q,EAAI6Q,MAAQ9F,EAAM8F,OAGd9F,EAAM+F,OACV9Q,EAAI8Q,KAAO/F,EAAM+F,MAEb/F,EAAMgG,QACV/Q,EAAI+Q,MAAQhG,EAAMgG,OAEdhG,EAAMiG,UACVhR,EAAIgR,QAAUjG,EAAMiG,SAGrBhI,EAAOyG,GAAY1E,GACb9G,EAAI,EAAGA,EAAI+E,EAAK9E,OAAQD,IAC7BuM,EAAMxH,EAAM/E,GACZ0H,EAAOD,GAAoBX,EAAOyF,GAC7BxN,GAAY2I,EAAM,WACtBgF,EAAQ3K,GAAS+E,EAAOyF,IAAY,GAAK,GACzC7E,EAAKnK,MAAQyO,GAAUlF,EAAOyF,GAAOG,EAAKP,EAAOC,GAAO,IAEzDxQ,GAAgBG,EAAKwQ,EAAK7E,GAE3B,OAAO3L,EA0CCiR,CAAWf,GAKnB,GAAc,UAFdxJ,EAAOK,GAAQmJ,IAGd,OAAO,IAAIgB,MAAOhB,GAEnB,GAAc,WAATxJ,EACJ,OAAO8I,GAAQU,EAAI7P,YAEpB,GAAc,QAATqG,EACJ,OAAO,IAAIyK,IAAKjB,GAEjB,GAAc,QAATxJ,EACJ,OAAO,IAAI0K,IAAKlB,GAEjB,GACU,WAATxJ,GACS,YAATA,GACS,WAATA,EAGA,OAAOwJ,EAAI9M,UAGZ,GADAuD,EAAOqJ,GAAatJ,GAEnB,OAAOC,EAAMuJ,GAGd,GACU,UAATxJ,GACS,WAATA,EAGA,MAA8B,mBAAlB5G,OAAOuR,OA1KrB,SAAwBnB,GACvB,IAAIE,EACAkB,EACA5K,EACA2J,EACA1E,EACAgF,EACAF,EACAxM,EAUJ,IARAmM,EAAQ,GACRC,EAAO,GAEPI,EAAM3Q,OAAOyR,OAAQjJ,GAAgB4H,IACrCE,EAAM9E,KAAM4E,GACZG,EAAK/E,KAAMmF,GAEXa,EAAQ9F,GAAe0E,GACjBjM,EAAI,EAAGA,EAAIqN,EAAMpN,OAAQD,IAC9ByC,EAAO4K,EAAOrN,GACd0H,EAAOD,GAAoBwE,EAAKxJ,GAC3B1D,GAAY2I,EAAM,WACtBgF,EAAQ3K,GAASkK,EAAIxJ,IAAY,GAAK,GACtCiF,EAAKnK,MAAQyO,GAAUC,EAAIxJ,GAAOiK,EAAKP,EAAOC,GAAO,IAEtDxQ,GAAgB4Q,EAAK/J,EAAMiF,GAW5B,OATM7L,OAAO0R,aAActB,IAC1BpQ,OAAO2R,kBAAmBhB,GAEtB3Q,OAAO4R,SAAUxB,IACrBpQ,OAAO6R,KAAMlB,GAET3Q,OAAO8R,SAAU1B,IACrBpQ,OAAOuR,OAAQZ,GAETA,EAuIEoB,CAAe3B,GAEhB,GAIR,GADAlH,EAAOyG,GAAYS,GACdI,EAAQ,EAEZ,IADAC,EAAS7J,EACHgK,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAE7B5I,EAAIoI,EADJM,EAAMxH,EAAM0H,IAIZhK,EAAOK,GAAQe,GAED,iBAANA,GACD,OAANA,GAEU,UAATpB,GACS,WAATA,GAEDH,GAAUuB,GAEM,WAAXyI,GACJ5E,EAAOD,GAAoBwE,EAAKM,GAC3BxN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQyO,GAAUnI,IAExBjI,GAAgBsQ,EAAMK,EAAK7E,IAE3BwE,EAAMK,GAAQP,GAAUnI,IAMd,KADZ7D,EAAImG,GAASgG,EAAOtI,KAMpB2I,EAAQzK,GAAS8B,GAAQ,IAAI/B,MAAO+B,EAAE5D,QAAW,GACjDkM,EAAM9E,KAAMxD,GACZuI,EAAK/E,KAAMmF,GACK,UAAXF,EACJJ,EAAMK,GAAQP,GAAUnI,EAAG2I,EAAKL,EAAOC,EAAMC,IAE7C3E,EAAOD,GAAoBwE,EAAKM,GAC3BxN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQyO,GAAUnI,EAAG2I,EAAKL,EAAOC,EAAMC,IAE7CzQ,GAAgBsQ,EAAMK,EAAK7E,KAd3BwE,EAAMK,GAAQH,EAAMpM,QAiBhB,GAAc,UAATyC,EACX,IAAMgK,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAE7BP,EADAK,EAAMxH,EAAM0H,IACER,EAAKM,QAGpB,IAAME,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAC7BF,EAAMxH,EAAM0H,GACZ/E,EAAOD,GAAoBwE,EAAKM,GAChC3Q,GAAgBsQ,EAAMK,EAAK7E,GAY7B,OATM7L,OAAO0R,aAActB,IAC1BpQ,OAAO2R,kBAAmBtB,GAEtBrQ,OAAO4R,SAAUxB,IACrBpQ,OAAO6R,KAAMxB,GAETrQ,OAAO8R,SAAU1B,IACrBpQ,OAAOuR,OAAQlB,GAETA,EAMR,IC3RInK,GAAUjE,GACVqG,GAAuBxG,GAAmD6B,YAC1EsE,GAAOlG,GACPoO,GDwRaA,GCtOjB,IAAA6B,GAnBA,SAAetQ,EAAO8O,GACrB,IAAInN,EACJ,GAAKkC,UAAUnB,OAAS,EAAI,CAC3B,IAAMkE,GAAsBkI,GAC3B,MAAM,IAAIhP,UAAW,oEAAsEgP,EAAQ,MAEpG,GAAe,IAAVA,EACJ,OAAO9O,OAGR8O,EAAQvI,GAGT,OADA5E,EAAQ6C,GAASxE,GAAY,IAAIuE,MAAOvE,EAAM0C,QAAW,GAClD+L,GAAUzO,EAAO2B,EAAK,CAAC3B,GAAQ,CAAC2B,GAAMmN,ICd9CxO,GALWC,GC5BPiE,GAAUjE,GA8Bd,IC9BI2B,GDmBJ,SAAmBlC,GAClB,MACkB,iBAAVA,GACG,OAAVA,IACCwE,GAASxE,ICtBR4F,GAAaxF,GACb0G,GAAiBzG,GACjBmB,GAAaa,EACbP,GAAcwG,EAKdiI,GAAkBjS,OAAOK,UAgF7B,IAAA6B,GAvCA,SAAwBR,GACvB,IAAI+G,EAGJ,QAAM7E,GAAUlC,OAIhB+G,EAAQD,GAAgB9G,MAOtBwB,GAAYxB,EAAO,gBAGpBwB,GAAYuF,EAAO,gBACnBnB,GAAYmB,EAAMjC,cACmB,sBAArChD,GAAaiF,EAAMjC,cAGnBtD,GAAYuF,EAAO,kBACnBnB,GAAYmB,EAAMyJ,iBAIjBzJ,IAAUwJ,IAzDb,SAAmBhR,GAClB,IAAIyP,EAGJ,IAAMA,KAAOzP,EACZ,IAAMiC,GAAYjC,EAAKyP,GACtB,OAAO,EAGT,OAAO,EAmDLyB,CAAUzQ,MCjFTkC,GCegB3B,GDdhBiB,GAAapB,EACbgC,GAAW/B,EAAsC4B,YAqCrD,wJEvCIU,GAAUpC,GACVoO,GAAOvO,GACPsQ,GFeJ,SAAmBC,EAAMC,GACxB,OAAM1O,GAAU0O,GAGXpP,GAAYoP,EAAS,SACzBD,EAAKE,IAAMD,EAAQC,KACbzO,GAAUuO,EAAKE,MACb,IAAI/Q,UAAW,qEAAuE6Q,EAAKE,IAAM,MAGrGrP,GAAYoP,EAAS,aACzBD,EAAKvB,QAAUwB,EAAQxB,SACjBhN,GAAUuO,EAAKvB,UACb,IAAItP,UAAW,yEAA2E6Q,EAAKvB,QAAU,MAG3G,KAdC,IAAItP,UAAW,iEAAmE8Q,EAAU,OEhBjGE,GAAWzO,GAwDf,IAAA0O,GAnCA,SAAkBH,GACjB,IAAID,EACAnS,EAGJ,GAFAmS,EAAOhC,GAAMmC,IACbtS,EAAMkS,GAAUC,EAAMC,GAErB,MAAMpS,EAEP,OAUA,WACC,IAEIwS,EACAvO,EAHA6M,EAAOzL,UAAW,GAClBgN,EAAMF,EAAKE,IAAM,SAASvB,EAG9B,IAAM7M,EAAI,EAAGA,EAAIoB,UAAUnB,OAAQD,IAClCoO,GAAO,UAAYI,mBAAoBpN,UAAWpB,IAInD,OAFAuO,EAAMrO,GAASgO,EAAKvB,QAAS,UAAWyB,GACxCG,EAAMrO,GAASqO,EAAK,WAAY1B,KCtC9B4B,GCbU3Q,GACCH,IDWGG,EAOL2Q,GAAwB,UALvB7Q,IAUd,IAAAC,GAAiB4Q,UEiFjB,WACC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAnP,EACA0M,EACAzM,EASJ,IANA0O,EAAUtN,UAAW,GACrBuN,EAASvN,UAAW,GAGpBwN,GADAG,EAAQ3N,UAAW,GADnB0N,GAHAD,EAAQzN,UAAW,IAGLnB,UAECA,OACfgP,EAAMN,EACA3O,EAAI,EAAGA,EAAI8O,EAAO9O,IAAM,CAI7B,GAHAkP,EAAIL,EAAO7O,GACXyM,EAAIrL,UAAWpB,EAAE,GAEH,WADdgP,EAAOD,EAAO/O,EAAE4O,IAEVnC,EAAI,EACRA,EAAI,EACOA,GAAKyC,IAChBzC,EAAIyC,EAAI,QAEH,GAAc,SAATF,EACNvC,EAAI,GACRA,GAAKyC,GACI,GAEG,KADXzC,GAAKyC,KAEJzC,GAAKyC,GAGIzC,GAAKyC,IAChBzC,GAAKyC,IACKA,IACTzC,GAAKyC,QAGD,GAAKzC,EAAI,GAAKA,GAAKyC,EACzB,MAAM,IAAIC,WAAYC,GAAQ,+FAAgGpP,EAAGyM,KAElI1M,EAAI2O,EAAS1O,IAGJ,GAAgB,IAAX2O,EACbM,GAAOxC,EAAI1M,EAEXkP,GAAOxC,EAAI1M,EAGb,OAAOkP"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 7edaeaa..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index b60f829..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From b0c1c69c5f811553835876ebf252088fd55384b6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 12:34:36 +0000 Subject: [PATCH 007/140] 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 | 62 +- benchmark/benchmark.js | 403 --- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 573 ----- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 -- manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 2689 +++++++++++++++++++++ stats_node.html | 2689 +++++++++++++++++++++ test/test.js | 403 --- 48 files changed, 5427 insertions(+), 5523 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 1286f26..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T00:46:37.612Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..319dc4e --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).sub2ind=r()}(this,(function(){"use strict";function t(t){var r=t.default;if("function"==typeof r){var e=function(){return r.apply(this,arguments)};e.prototype=r.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(t).forEach((function(r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})})),e}var r="function"==typeof Object.defineProperty?Object.defineProperty:null;var e=function(){try{return r({},"x",{}),!0}catch(t){return!1}},n=Object.defineProperty,o=Object.prototype,i=o.toString,u=o.__defineGetter__,a=o.__defineSetter__,f=o.__lookupGetter__,c=o.__lookupSetter__;var s=function(t,r,e){var n,s,l,h;if("object"!=typeof t||null===t||"[object Array]"===i.call(t))throw new TypeError("invalid argument. First argument must be an object. Value: `"+t+"`.");if("object"!=typeof e||null===e||"[object Array]"===i.call(e))throw new TypeError("invalid argument. Property descriptor must be an object. Value: `"+e+"`.");if((s="value"in e)&&(f.call(t,r)||c.call(t,r)?(n=t.__proto__,t.__proto__=o,delete t[r],t[r]=e.value,t.__proto__=n):t[r]=e.value),l="get"in e,h="set"in e,s&&(l||h))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return l&&u&&u.call(t,r,e.get),h&&a&&a.call(t,r,e.set),t},l=n,h=s,p=e()?l:h,y=p;var v=function(t,r,e){y(t,r,{configurable:!1,enumerable:!1,writable:!1,value:e})},g=v;var w=function(t){return"string"==typeof t};var d=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var b=function(){return d&&"symbol"==typeof Symbol.toStringTag},m=Object.prototype.toString,A=m;var E=function(t){return A.call(t)},_=Object.prototype.hasOwnProperty;var O=function(t,r){return null!=t&&_.call(t,r)},P="function"==typeof Symbol?Symbol.toStringTag:"",j=O,R=P,T=m;var U=E,S=function(t){var r,e,n;if(null==t)return T.call(t);e=t[R],r=j(t,R);try{t[R]=void 0}catch(r){return T.call(t)}return n=T.call(t),r?t[R]=e:delete t[R],n},I=b()?S:U,B=String.prototype.valueOf;var Y=I,x=function(t){try{return B.call(t),!0}catch(t){return!1}},C=b();var M=function(t){return"object"==typeof t&&(t instanceof String||(C?x(t):"[object String]"===Y(t)))},L=w,F=M;var D=g,N=function(t){return L(t)||F(t)},k=M;D(N,"isPrimitive",w),D(N,"isObject",k);var V=N,z=V.isPrimitive,G=/[-\/\\^$*+?.()|[\]{}]/g;var X=function(t){var r,e;if(!z(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");if("/"===t[0])for(e=t.length-1;e>=0&&"/"!==t[e];e--);return void 0===e||e<=0?t.replace(G,"\\$&"):(r=(r=t.substring(1,e)).replace(G,"\\$&"),t=t[0]+r+t.substring(e))},$=/./;var H=function(t){return"boolean"==typeof t},W=Boolean.prototype.toString;var q=I,J=function(t){try{return W.call(t),!0}catch(t){return!1}},Z=b();var K=function(t){return"object"==typeof t&&(t instanceof Boolean||(Z?J(t):"[object Boolean]"===q(t)))},Q=H,tt=K;var rt=g,et=function(t){return Q(t)||tt(t)},nt=K;rt(et,"isPrimitive",H),rt(et,"isObject",nt);var ot=et;var it=function(){return new Function("return this;")()},ut="object"==typeof self?self:null,at="object"==typeof window?window:null,ft="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},ct="object"==typeof ft?ft:null;module.exports=ct;var st=ot.isPrimitive,lt=it,ht=ut,pt=at,yt=t(Object.freeze({__proto__:null}));var vt=function(t){if(arguments.length){if(!st(t))throw new TypeError("invalid argument. Must provide a boolean primitive. Value: `"+t+"`.");if(t)return lt()}if(ht)return ht;if(pt)return pt;if(yt)return yt;throw new Error("unexpected error. Unable to resolve global object.")},gt=vt(),wt=gt.document&>.document.childNodes,dt=Int8Array,bt=$,mt=wt,At=dt;var Et=function(){return"function"==typeof bt||"object"==typeof At||"function"==typeof mt};var _t=function(){return/^\s*function\s*([^(]*)/i},Ot=_t;g(Ot,"REGEXP",_t());var Pt=Ot,jt=I;var Rt=Array.isArray?Array.isArray:function(t){return"[object Array]"===jt(t)},Tt=Rt;var Ut=function(t){return null!==t&&"object"==typeof t};g(Ut,"isObjectLikeArray",function(t){if("function"!=typeof t)throw new TypeError("invalid argument. Must provide a function. Value: `"+t+"`.");return function(r){var e,n;if(!Tt(r))return!1;if(0===(e=r.length))return!1;for(n=0;ndr&&br(t)},Ar=hr.isPrimitive,Er=mr;var _r=function(t){return Ar(t)&&Er(t)},Or=hr.isObject,Pr=mr;var jr=function(t){return Or(t)&&Pr(t.valueOf())},Rr=_r,Tr=jr;var Ur=g,Sr=function(t){return Rr(t)||Tr(t)},Ir=jr;Ur(Sr,"isPrimitive",_r),Ur(Sr,"isObject",Ir);var Br=Sr,Yr=Br.isPrimitive;var xr=function(t){return Yr(t)&&t>=0},Cr=Br.isObject;var Mr=function(t){return Cr(t)&&t.valueOf()>=0},Lr=xr,Fr=Mr;var Dr=g,Nr=function(t){return Lr(t)||Fr(t)},kr=Mr;Dr(Nr,"isPrimitive",xr),Dr(Nr,"isObject",kr);var Vr=Nr,zr=Object.getPrototypeOf;var Gr=function(t){return t.__proto__},Xr=I,$r=Gr;var Hr=function(t){var r=$r(t);return r||null===r?r:"[object Function]"===Xr(t.constructor)?t.constructor.prototype:t instanceof Object?Object.prototype:null},Wr=zr,qr=Hr,Jr=zt(Object.getPrototypeOf)?Wr:qr;var Zr=function(t){return null==t?null:(t=Object(t),Jr(t))},Kr=Zr,Qr=I;var te=function(t){if("object"!=typeof t||null===t)return!1;if(t instanceof Error)return!0;for(;t;){if("[object Error]"===Qr(t))return!0;t=Kr(t)}return!1};var re=function(){return/^\/((?:\\\/|[^\/])+)\/([imgy]*)$/},ee=re;g(ee,"REGEXP",re());var ne=V.isPrimitive,oe=ee;var ie=function(t){if(!ne(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");return(t=oe().exec(t))?new RegExp(t[1],t[2]):null};var ue=function(t){return t!=t},ae=hr.isPrimitive,fe=ue;var ce=function(t){return ae(t)&&fe(t)},se=hr.isObject,le=ue;var he=function(t){return se(t)&&le(t.valueOf())},pe=ce,ye=he;var ve=g,ge=function(t){return pe(t)||ye(t)},we=he;ve(ge,"isPrimitive",ce),ve(ge,"isObject",we);var de=ge,be=gr;var me=de,Ae=function(t){return"object"==typeof t&&null!==t&&"number"==typeof t.length&&be(t.length)&&t.length>=0&&t.length<=9007199254740991},Ee=V.isPrimitive,_e=Br.isPrimitive;var Oe=function(t,r,e){var n,o;if(!Ae(t)&&!Ee(t))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+t+"`.");if(0===(n=t.length))return-1;if(3===arguments.length){if(!_e(e))throw new TypeError("invalid argument. `fromIndex` must be an integer. Value: `"+e+"`.");if(e>=0){if(e>=n)return-1;o=e}else(o=n+e)<0&&(o=0)}else o=0;if(me(r)){for(;o=0&&r=0&&t.length<=4294967295&&Ge(t,"callee")&&!Xe(t,"callee")},qe=We,Je=je,Ze=Array.prototype.slice;var Ke=function(t){return qe(t)?Je(Ze.call(t)):Je(t)};var Qe=ze((function(){}),"prototype"),tn=!ze({toString:null},"toString");var rn,en=function(t){return t.constructor&&t.constructor.prototype===t},nn="undefined"==typeof window?void 0:window,on=O,un=Pe,an=kt,fn=en,cn=["console","external","frame","frameElement","frames","innerHeight","innerWidth","outerHeight","outerWidth","pageXOffset","pageYOffset","parent","scrollLeft","scrollTop","scrollX","scrollY","self","webkitIndexedDB","webkitStorageInfo","window"],sn=nn;rn=function(){var t;if("undefined"===an(sn))return!1;for(t in sn)try{-1===un(cn,t)&&on(sn,t)&&null!==sn[t]&&"object"===an(sn[t])&&fn(sn[t])}catch(t){return!0}return!1}();var ln="undefined"!=typeof window,hn=rn,pn=en,yn=ln;var vn=St,gn=O,wn=We,dn=Qe,bn=tn,mn=function(t){if(!1===yn&&!hn)return pn(t);try{return pn(t)}catch(t){return!1}},An=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"];var En=je,_n=Ke,On=function(t){var r,e,n,o,i,u,a;if(o=[],wn(t)){for(a=0;a0&&!gn(t,"0"))for(a=0;a!1})),Cn=[],Mn=[],Ln="undefined"!=typeof Uint8Array?Uint8Array:Array,Fn=!1;function Dn(){Fn=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=0,e=t.length;r>18&63]+Cn[o>>12&63]+Cn[o>>6&63]+Cn[63&o]);return i.join("")}function kn(t){var r;Fn||Dn();for(var e=t.length,n=e%3,o="",i=[],u=16383,a=0,f=e-n;af?f:a+u));return 1===n?(r=t[e-1],o+=Cn[r>>2],o+=Cn[r<<4&63],o+="=="):2===n&&(r=(t[e-2]<<8)+t[e-1],o+=Cn[r>>10],o+=Cn[r>>4&63],o+=Cn[r<<2&63],o+="="),i.push(o),i.join("")}function Vn(t,r,e,n,o){var i,u,a=8*o-n-1,f=(1<>1,s=-7,l=e?o-1:0,h=e?-1:1,p=t[r+l];for(l+=h,i=p&(1<<-s)-1,p>>=-s,s+=a;s>0;i=256*i+t[r+l],l+=h,s-=8);for(u=i&(1<<-s)-1,i>>=-s,s+=n;s>0;u=256*u+t[r+l],l+=h,s-=8);if(0===i)i=1-c;else{if(i===f)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),i-=c}return(p?-1:1)*u*Math.pow(2,i-n)}function zn(t,r,e,n,o,i){var u,a,f,c=8*i-o-1,s=(1<>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,y=n?1:-1,v=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,u=s):(u=Math.floor(Math.log(r)/Math.LN2),r*(f=Math.pow(2,-u))<1&&(u--,f*=2),(r+=u+l>=1?h/f:h*Math.pow(2,1-l))*f>=2&&(u++,f/=2),u+l>=s?(a=0,u=s):u+l>=1?(a=(r*f-1)*Math.pow(2,o),u+=l):(a=r*Math.pow(2,l-1)*Math.pow(2,o),u=0));o>=8;t[e+p]=255&a,p+=y,a/=256,o-=8);for(u=u<0;t[e+p]=255&u,p+=y,u/=256,c-=8);t[e+p-y]|=128*v}var Gn={}.toString,Xn=Array.isArray||function(t){return"[object Array]"==Gn.call(t)};qn.TYPED_ARRAY_SUPPORT=void 0===ft.TYPED_ARRAY_SUPPORT||ft.TYPED_ARRAY_SUPPORT;var $n=Hn();function Hn(){return qn.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Wn(t,r){if(Hn()=Hn())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Hn().toString(16)+" bytes");return 0|t}function ro(t){return!(null==t||!t._isBuffer)}function eo(t,r){if(ro(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return So(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return Io(t).length;default:if(n)return So(t).length;r=(""+r).toLowerCase(),n=!0}}function no(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return bo(this,r,e);case"utf8":case"utf-8":return yo(this,r,e);case"ascii":return go(this,r,e);case"latin1":case"binary":return wo(this,r,e);case"base64":return po(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return mo(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function oo(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function io(t,r,e,n,o){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0){if(!o)return-1;e=0}if("string"==typeof r&&(r=qn.from(r,n)),ro(r))return 0===r.length?-1:uo(t,r,e,n,o);if("number"==typeof r)return r&=255,qn.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):uo(t,[r],e,n,o);throw new TypeError("val must be string, number or Buffer")}function uo(t,r,e,n,o){var i,u=1,a=t.length,f=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,a/=2,f/=2,e/=2}function c(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(o){var s=-1;for(i=e;ia&&(e=a-f),i=e;i>=0;i--){for(var l=!0,h=0;ho&&(n=o):n=o;var i=r.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var u=0;u>8,o=e%256,i.push(o),i.push(n);return i}(r,t.length-e),t,e,n)}function po(t,r,e){return 0===r&&e===t.length?kn(t):kn(t.slice(r,e))}function yo(t,r,e){e=Math.min(t.length,e);for(var n=[],o=r;o239?4:c>223?3:c>191?2:1;if(o+l<=e)switch(l){case 1:c<128&&(s=c);break;case 2:128==(192&(i=t[o+1]))&&(f=(31&c)<<6|63&i)>127&&(s=f);break;case 3:i=t[o+1],u=t[o+2],128==(192&i)&&128==(192&u)&&(f=(15&c)<<12|(63&i)<<6|63&u)>2047&&(f<55296||f>57343)&&(s=f);break;case 4:i=t[o+1],u=t[o+2],a=t[o+3],128==(192&i)&&128==(192&u)&&128==(192&a)&&(f=(15&c)<<18|(63&i)<<12|(63&u)<<6|63&a)>65535&&f<1114112&&(s=f)}null===s?(s=65533,l=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=l}return function(t){var r=t.length;if(r<=vo)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),""},qn.prototype.compare=function(t,r,e,n,o){if(!ro(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),r<0||e>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&r>=e)return 0;if(n>=o)return-1;if(r>=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),a=Math.min(i,u),f=this.slice(n,o),c=t.slice(r,e),s=0;so)&&(e=o),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return ao(this,t,r,e);case"utf8":case"utf-8":return fo(this,t,r,e);case"ascii":return co(this,t,r,e);case"latin1":case"binary":return so(this,t,r,e);case"base64":return lo(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ho(this,t,r,e);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},qn.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var vo=4096;function go(t,r,e){var n="";e=Math.min(t.length,e);for(var o=r;on)&&(e=n);for(var o="",i=r;ie)throw new RangeError("Trying to access beyond buffer length")}function Eo(t,r,e,n,o,i){if(!ro(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>o||rt.length)throw new RangeError("Index out of range")}function _o(t,r,e,n){r<0&&(r=65535+r+1);for(var o=0,i=Math.min(t.length-e,2);o>>8*(n?o:1-o)}function Oo(t,r,e,n){r<0&&(r=4294967295+r+1);for(var o=0,i=Math.min(t.length-e,4);o>>8*(n?o:3-o)&255}function Po(t,r,e,n,o,i){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function jo(t,r,e,n,o){return o||Po(t,0,e,4),zn(t,r,e,n,23,4),e+4}function Ro(t,r,e,n,o){return o||Po(t,0,e,8),zn(t,r,e,n,52,8),e+8}qn.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(o*=256);)n+=this[t+--r]*o;return n},qn.prototype.readUInt8=function(t,r){return r||Ao(t,1,this.length),this[t]},qn.prototype.readUInt16LE=function(t,r){return r||Ao(t,2,this.length),this[t]|this[t+1]<<8},qn.prototype.readUInt16BE=function(t,r){return r||Ao(t,2,this.length),this[t]<<8|this[t+1]},qn.prototype.readUInt32LE=function(t,r){return r||Ao(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},qn.prototype.readUInt32BE=function(t,r){return r||Ao(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},qn.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||Ao(t,r,this.length);for(var n=this[t],o=1,i=0;++i=(o*=128)&&(n-=Math.pow(2,8*r)),n},qn.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||Ao(t,r,this.length);for(var n=r,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*r)),i},qn.prototype.readInt8=function(t,r){return r||Ao(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},qn.prototype.readInt16LE=function(t,r){r||Ao(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},qn.prototype.readInt16BE=function(t,r){r||Ao(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},qn.prototype.readInt32LE=function(t,r){return r||Ao(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},qn.prototype.readInt32BE=function(t,r){return r||Ao(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},qn.prototype.readFloatLE=function(t,r){return r||Ao(t,4,this.length),Vn(this,t,!0,23,4)},qn.prototype.readFloatBE=function(t,r){return r||Ao(t,4,this.length),Vn(this,t,!1,23,4)},qn.prototype.readDoubleLE=function(t,r){return r||Ao(t,8,this.length),Vn(this,t,!0,52,8)},qn.prototype.readDoubleBE=function(t,r){return r||Ao(t,8,this.length),Vn(this,t,!1,52,8)},qn.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||Eo(this,t,r,e,Math.pow(2,8*e)-1,0);var o=1,i=0;for(this[r]=255&t;++i=0&&(i*=256);)this[r+o]=t/i&255;return r+e},qn.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,1,255,0),qn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},qn.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,65535,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):_o(this,t,r,!0),r+2},qn.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,65535,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):_o(this,t,r,!1),r+2},qn.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,4294967295,0),qn.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):Oo(this,t,r,!0),r+4},qn.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,4294967295,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Oo(this,t,r,!1),r+4},qn.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Eo(this,t,r,e,o-1,-o)}var i=0,u=1,a=0;for(this[r]=255&t;++i>0)-a&255;return r+e},qn.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Eo(this,t,r,e,o-1,-o)}var i=e-1,u=1,a=0;for(this[r+i]=255&t;--i>=0&&(u*=256);)t<0&&0===a&&0!==this[r+i+1]&&(a=1),this[r+i]=(t/u>>0)-a&255;return r+e},qn.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,1,127,-128),qn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},qn.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,32767,-32768),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):_o(this,t,r,!0),r+2},qn.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,32767,-32768),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):_o(this,t,r,!1),r+2},qn.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,2147483647,-2147483648),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):Oo(this,t,r,!0),r+4},qn.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Oo(this,t,r,!1),r+4},qn.prototype.writeFloatLE=function(t,r,e){return jo(this,t,r,!0,e)},qn.prototype.writeFloatBE=function(t,r,e){return jo(this,t,r,!1,e)},qn.prototype.writeDoubleLE=function(t,r,e){return Ro(this,t,r,!0,e)},qn.prototype.writeDoubleBE=function(t,r,e){return Ro(this,t,r,!1,e)},qn.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--o)t[o+r]=this[o+e];else if(i<1e3||!qn.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(i=r;i55295&&e<57344){if(!o){if(e>56319){(r-=3)>-1&&i.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&i.push(239,191,189);continue}o=e;continue}if(e<56320){(r-=3)>-1&&i.push(239,191,189),o=e;continue}e=65536+(o-55296<<10|e-56320)}else o&&(r-=3)>-1&&i.push(239,191,189);if(o=null,e<128){if((r-=1)<0)break;i.push(e)}else if(e<2048){if((r-=2)<0)break;i.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;i.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;i.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return i}function Io(t){return function(t){var r,e,n,o,i,u;Fn||Dn();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[a-2]?2:"="===t[a-1]?1:0,u=new Ln(3*a/4-i),n=i>0?a-4:a;var f=0;for(r=0,e=0;r>16&255,u[f++]=o>>8&255,u[f++]=255&o;return 2===i?(o=Mn[t.charCodeAt(r)]<<2|Mn[t.charCodeAt(r+1)]>>4,u[f++]=255&o):1===i&&(o=Mn[t.charCodeAt(r)]<<10|Mn[t.charCodeAt(r+1)]<<4|Mn[t.charCodeAt(r+2)]>>2,u[f++]=o>>8&255,u[f++]=255&o),u}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(To,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Bo(t,r,e,n){for(var o=0;o=r.length||o>=t.length);++o)r[o+e]=t[o];return o}function Yo(t){return null!=t&&(!!t._isBuffer||xo(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&xo(t.slice(0,0))}(t))}function xo(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var Co=t(Object.freeze({__proto__:null,Buffer:qn,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),qn.alloc(+t)},isBuffer:Yo,kMaxLength:$n})).Buffer,Mo=function(){throw new Error("not implemented")},Lo=xn()?Co:Mo,Fo=zt(Lo.from),Do=Bt,No=Lo;var ko=function(t){if(!Do(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return No.from(t)},Vo=Bt,zo=Lo;var Go=function(t){if(!Vo(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return new zo(t)},Xo=Fo?ko:Go,$o=I,Ho="function"==typeof Int8Array;var Wo="function"==typeof Int8Array?Int8Array:null,qo=function(t){return Ho&&t instanceof Int8Array||"[object Int8Array]"===$o(t)},Jo=Wo;var Zo=function(){var t,r;if("function"!=typeof Jo)return!1;try{r=new Jo([1,3.14,-3.14,128]),t=qo(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-128===r[3]}catch(r){t=!1}return t};var Ko="function"==typeof Int8Array?Int8Array:void 0,Qo=function(){throw new Error("not implemented")},ti=Zo()?Ko:Qo,ri=I,ei="function"==typeof Uint8Array;var ni="function"==typeof Uint8Array?Uint8Array:null,oi=function(t){return ei&&t instanceof Uint8Array||"[object Uint8Array]"===ri(t)},ii=ni;var ui=function(){var t,r;if("function"!=typeof ii)return!1;try{r=new ii(r=[1,3.14,-3.14,256,257]),t=oi(r)&&1===r[0]&&3===r[1]&&253===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var ai="function"==typeof Uint8Array?Uint8Array:void 0,fi=function(){throw new Error("not implemented")},ci=ui()?ai:fi,si=I,li="function"==typeof Uint8ClampedArray;var hi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:null,pi=function(t){return li&&t instanceof Uint8ClampedArray||"[object Uint8ClampedArray]"===si(t)},yi=hi;var vi=function(){var t,r;if("function"!=typeof yi)return!1;try{r=new yi([-1,0,1,3.14,4.99,255,256]),t=pi(r)&&0===r[0]&&0===r[1]&&1===r[2]&&3===r[3]&&5===r[4]&&255===r[5]&&255===r[6]}catch(r){t=!1}return t};var gi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:void 0,wi=function(){throw new Error("not implemented")},di=vi()?gi:wi,bi=I,mi="function"==typeof Int16Array;var Ai="function"==typeof Int16Array?Int16Array:null,Ei=function(t){return mi&&t instanceof Int16Array||"[object Int16Array]"===bi(t)},_i=Ai;var Oi=function(){var t,r;if("function"!=typeof _i)return!1;try{r=new _i([1,3.14,-3.14,32768]),t=Ei(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-32768===r[3]}catch(r){t=!1}return t};var Pi="function"==typeof Int16Array?Int16Array:void 0,ji=function(){throw new Error("not implemented")},Ri=Oi()?Pi:ji,Ti=I,Ui="function"==typeof Uint16Array;var Si="function"==typeof Uint16Array?Uint16Array:null,Ii=function(t){return Ui&&t instanceof Uint16Array||"[object Uint16Array]"===Ti(t)},Bi=Si;var Yi=function(){var t,r;if("function"!=typeof Bi)return!1;try{r=new Bi(r=[1,3.14,-3.14,65536,65537]),t=Ii(r)&&1===r[0]&&3===r[1]&&65533===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var xi="function"==typeof Uint16Array?Uint16Array:void 0,Ci=function(){throw new Error("not implemented")},Mi=Yi()?xi:Ci,Li=I,Fi="function"==typeof Int32Array;var Di="function"==typeof Int32Array?Int32Array:null,Ni=function(t){return Fi&&t instanceof Int32Array||"[object Int32Array]"===Li(t)},ki=Di;var Vi=function(){var t,r;if("function"!=typeof ki)return!1;try{r=new ki([1,3.14,-3.14,2147483648]),t=Ni(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-2147483648===r[3]}catch(r){t=!1}return t};var zi="function"==typeof Int32Array?Int32Array:void 0,Gi=function(){throw new Error("not implemented")},Xi=Vi()?zi:Gi,$i=I,Hi="function"==typeof Uint32Array;var Wi="function"==typeof Uint32Array?Uint32Array:null,qi=function(t){return Hi&&t instanceof Uint32Array||"[object Uint32Array]"===$i(t)},Ji=Wi;var Zi=function(){var t,r;if("function"!=typeof Ji)return!1;try{r=new Ji(r=[1,3.14,-3.14,4294967296,4294967297]),t=qi(r)&&1===r[0]&&3===r[1]&&4294967293===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var Ki="function"==typeof Uint32Array?Uint32Array:void 0,Qi=function(){throw new Error("not implemented")},tu=Zi()?Ki:Qi,ru=I,eu="function"==typeof Float32Array;var nu="function"==typeof Float32Array?Float32Array:null,ou=function(t){return eu&&t instanceof Float32Array||"[object Float32Array]"===ru(t)},iu=pr,uu=nu;var au=function(){var t,r;if("function"!=typeof uu)return!1;try{r=new uu([1,3.14,-3.14,5e40]),t=ou(r)&&1===r[0]&&3.140000104904175===r[1]&&-3.140000104904175===r[2]&&r[3]===iu}catch(r){t=!1}return t};var fu="function"==typeof Float32Array?Float32Array:void 0,cu=function(){throw new Error("not implemented")},su=au()?fu:cu,lu=I,hu="function"==typeof Float64Array;var pu="function"==typeof Float64Array?Float64Array:null,yu=function(t){return hu&&t instanceof Float64Array||"[object Float64Array]"===lu(t)},vu=pu;var gu=function(){var t,r;if("function"!=typeof vu)return!1;try{r=new vu([1,3.14,-3.14,NaN]),t=yu(r)&&1===r[0]&&3.14===r[1]&&-3.14===r[2]&&r[3]!=r[3]}catch(r){t=!1}return t};var wu,du="function"==typeof Float64Array?Float64Array:void 0,bu=function(){throw new Error("not implemented")};wu=gu()?du:bu;var mu=ti,Au=ci,Eu=di,_u=Ri,Ou=Mi,Pu=Xi,ju=tu,Ru=su,Tu=wu;function Uu(t){return new mu(t)}function Su(t){return new Au(t)}function Iu(t){return new Eu(t)}function Bu(t){return new _u(t)}function Yu(t){return new Ou(t)}function xu(t){return new Pu(t)}function Cu(t){return new ju(t)}function Mu(t){return new Ru(t)}function Lu(t){return new Tu(t)}var Fu=O,Du=Rt,Nu=Bt,ku=te,Vu=kt,zu=ie,Gu=Pe,Xu=Pn,$u=Un,Hu=Yn,Wu=Zr,qu=p,Ju=Xo,Zu={int8array:Uu,uint8array:Su,uint8clampedarray:Iu,int16array:Bu,uint16array:Yu,int32array:xu,uint32array:Cu,float32array:Mu,float64array:Lu};function Ku(t,r,e,n,o){var i,u,a,f,c,s,l,h,p,y;if(o-=1,"object"!=typeof t||null===t)return t;if(Nu(t))return Ju(t);if(ku(t))return function(t){var r,e,n,o,i,u,a=[],f=[];for(i=new t.constructor(t.message),a.push(t),f.push(i),t.stack&&(i.stack=t.stack),t.code&&(i.code=t.code),t.errno&&(i.errno=t.errno),t.syscall&&(i.syscall=t.syscall),r=Xu(t),u=0;u0)for(i=a,y=0;y1){if(!ta(r))throw new TypeError("invalid argument. `level` must be a nonnegative integer. Value: `"+r+"`.");if(0===r)return t}else r=ra;return e=Qu(t)?new Array(t.length):{},ea(t,e,[t],[e],r)},oa=na,ia=Rt;var ua=function(t){return"object"==typeof t&&null!==t&&!ia(t)},aa=zt,fa=Zr,ca=O,sa=I,la=Object.prototype;var ha=function(t){var r;return!!ua(t)&&(!(r=fa(t))||!ca(t,"constructor")&&ca(r,"constructor")&&aa(r.constructor)&&"[object Function]"===sa(r.constructor)&&ca(r,"isPrototypeOf")&&aa(r.isPrototypeOf)&&(r===la||function(t){var r;for(r in t)if(!ca(t,r))return!1;return!0}(t)))},pa=ha,ya=O,va=V.isPrimitive;var ga={url:"https://stdlib.io/docs/api/latest/error-decoder.html",message:"Minified stdlib error code: {{code}}. Visit {{url}} for the full message."},wa=Kt,da=oa,ba=function(t,r){return pa(r)?ya(r,"url")&&(t.url=r.url,!va(t.url))?new TypeError("invalid option. `url` option must be a string primitive. Option: `"+t.url+"`."):ya(r,"message")&&(t.message=r.message,!va(t.message))?new TypeError("invalid option. `message` option must be a string primitive. Option: `"+t.message+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.")},ma=ga;var Aa=function(t){var r,e;if(r=da(ma),e=ba(r,t))throw e;return function(){var t,e,n=arguments[0],o=r.url+"?code="+n;for(e=1;e=f&&(s=f-1);else if("wrap"===u)s<0?(s+=f)<0&&0!==(s%=f)&&(s+=f):s>=f&&(s-=f)>=f&&(s%=f);else if(s<0||s>=f)throw new RangeError(_a("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",l,s));(c=t[l])<0&&0===r?a-=s*c:a+=s*c}return a}})); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..75b90f6 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/utils-define-property/lib/define_property.js","../node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js","../node_modules/@stdlib/utils-define-property/lib/builtin.js","../node_modules/@stdlib/utils-define-property/lib/polyfill.js","../node_modules/@stdlib/utils-define-property/lib/index.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/primitive.js","../node_modules/@stdlib/assert-has-symbol-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostring.js","../node_modules/@stdlib/utils-native-class/lib/native_class.js","../node_modules/@stdlib/assert-has-own-property/lib/main.js","../node_modules/@stdlib/assert-has-own-property/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostringtag.js","../node_modules/@stdlib/utils-native-class/lib/polyfill.js","../node_modules/@stdlib/utils-native-class/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/try2valueof.js","../node_modules/@stdlib/assert-is-string/lib/valueof.js","../node_modules/@stdlib/assert-is-string/lib/object.js","../node_modules/@stdlib/assert-is-string/lib/main.js","../node_modules/@stdlib/assert-is-string/lib/index.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/main.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/re.js","../node_modules/@stdlib/assert-is-boolean/lib/primitive.js","../node_modules/@stdlib/assert-is-boolean/lib/try2serialize.js","../node_modules/@stdlib/assert-is-boolean/lib/tostring.js","../node_modules/@stdlib/assert-is-boolean/lib/object.js","../node_modules/@stdlib/assert-is-boolean/lib/main.js","../node_modules/@stdlib/assert-is-boolean/lib/index.js","../node_modules/@stdlib/utils-global/lib/codegen.js","../node_modules/@stdlib/utils-global/lib/self.js","../node_modules/@stdlib/utils-global/lib/window.js","../node_modules/@stdlib/utils-global/lib/global.js","../node_modules/@stdlib/utils-global/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/nodelist.js","../node_modules/@stdlib/utils-global/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/typedarray.js","../node_modules/@stdlib/utils-type-of/lib/check.js","../node_modules/@stdlib/regexp-function-name/lib/main.js","../node_modules/@stdlib/regexp-function-name/lib/index.js","../node_modules/@stdlib/regexp-function-name/lib/regexp.js","../node_modules/@stdlib/assert-is-array/lib/main.js","../node_modules/@stdlib/assert-is-array/lib/index.js","../node_modules/@stdlib/assert-tools-array-function/lib/arrayfcn.js","../node_modules/@stdlib/assert-is-object-like/lib/main.js","../node_modules/@stdlib/assert-is-object-like/lib/index.js","../node_modules/@stdlib/assert-is-buffer/lib/main.js","../node_modules/@stdlib/assert-is-buffer/lib/index.js","../node_modules/@stdlib/utils-constructor-name/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/typeof.js","../node_modules/@stdlib/utils-constructor-name/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/polyfill.js","../node_modules/@stdlib/utils-type-of/lib/index.js","../node_modules/@stdlib/assert-is-function/lib/main.js","../node_modules/@stdlib/assert-is-function/lib/index.js","../node_modules/@stdlib/assert-is-regexp/lib/try2exec.js","../node_modules/@stdlib/assert-is-regexp/lib/exec.js","../node_modules/@stdlib/assert-is-regexp/lib/main.js","../node_modules/@stdlib/string-replace/lib/replace.js","../node_modules/@stdlib/string-replace/lib/index.js","../node_modules/@stdlib/assert-is-number/lib/primitive.js","../node_modules/@stdlib/number-ctor/lib/index.js","../node_modules/@stdlib/number-ctor/lib/number.js","../node_modules/@stdlib/assert-is-number/lib/try2serialize.js","../node_modules/@stdlib/assert-is-number/lib/tostring.js","../node_modules/@stdlib/assert-is-number/lib/object.js","../node_modules/@stdlib/assert-is-number/lib/main.js","../node_modules/@stdlib/assert-is-number/lib/index.js","../node_modules/@stdlib/constants-float64-pinf/lib/index.js","../node_modules/@stdlib/constants-float64-ninf/lib/index.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/is_integer.js","../node_modules/@stdlib/math-base-special-floor/lib/main.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-integer/lib/integer.js","../node_modules/@stdlib/assert-is-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-integer/lib/object.js","../node_modules/@stdlib/assert-is-integer/lib/main.js","../node_modules/@stdlib/assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/object.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/main.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/index.js","../node_modules/@stdlib/utils-get-prototype-of/lib/native.js","../node_modules/@stdlib/utils-get-prototype-of/lib/proto.js","../node_modules/@stdlib/utils-get-prototype-of/lib/polyfill.js","../node_modules/@stdlib/utils-get-prototype-of/lib/detect.js","../node_modules/@stdlib/utils-get-prototype-of/lib/get_prototype_of.js","../node_modules/@stdlib/utils-get-prototype-of/lib/index.js","../node_modules/@stdlib/assert-is-error/lib/main.js","../node_modules/@stdlib/assert-is-error/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/main.js","../node_modules/@stdlib/regexp-regexp/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/regexp.js","../node_modules/@stdlib/utils-regexp-from-string/lib/from_string.js","../node_modules/@stdlib/utils-regexp-from-string/lib/index.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/primitive.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-nan/lib/object.js","../node_modules/@stdlib/assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-collection/lib/main.js","../node_modules/@stdlib/utils-index-of/lib/index_of.js","../node_modules/@stdlib/constants-array-max-typed-array-length/lib/index.js","../node_modules/@stdlib/utils-index-of/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin.js","../node_modules/@stdlib/utils-keys/lib/has_arguments_bug.js","../node_modules/@stdlib/utils-keys/lib/has_builtin.js","../node_modules/@stdlib/assert-is-arguments/lib/main.js","../node_modules/@stdlib/assert-is-arguments/lib/detect.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/has_string_enumerability_bug.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/native.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/main.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/index.js","../node_modules/@stdlib/assert-is-arguments/lib/polyfill.js","../node_modules/@stdlib/assert-is-arguments/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin_wrapper.js","../node_modules/@stdlib/utils-noop/lib/noop.js","../node_modules/@stdlib/utils-keys/lib/has_enumerable_prototype_bug.js","../node_modules/@stdlib/utils-keys/lib/has_non_enumerable_properties_bug.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype.js","../node_modules/@stdlib/utils-keys/lib/has_automation_equality_bug.js","../node_modules/@stdlib/utils-keys/lib/window.js","../node_modules/@stdlib/utils-keys/lib/has_window.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype_wrapper.js","../node_modules/@stdlib/utils-keys/lib/polyfill.js","../node_modules/@stdlib/utils-keys/lib/main.js","../node_modules/@stdlib/utils-keys/lib/index.js","../node_modules/@stdlib/utils-property-names/lib/has_builtin.js","../node_modules/@stdlib/utils-property-names/lib/builtin.js","../node_modules/@stdlib/utils-property-names/lib/polyfill.js","../node_modules/@stdlib/utils-property-names/lib/index.js","../node_modules/@stdlib/utils-property-descriptor/lib/has_builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/polyfill.js","../node_modules/@stdlib/utils-property-descriptor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/polyfill.js","../node_modules/@stdlib/buffer-ctor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/buffer.js","../node_modules/@stdlib/buffer-from-buffer/lib/has_from.js","../node_modules/@stdlib/buffer-from-buffer/lib/main.js","../node_modules/@stdlib/buffer-from-buffer/lib/polyfill.js","../node_modules/@stdlib/buffer-from-buffer/lib/index.js","../node_modules/@stdlib/assert-is-int8array/lib/main.js","../node_modules/@stdlib/assert-has-int8array-support/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/main.js","../node_modules/@stdlib/constants-int8-min/lib/index.js","../node_modules/@stdlib/array-int8/lib/polyfill.js","../node_modules/@stdlib/array-int8/lib/index.js","../node_modules/@stdlib/array-int8/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8array/lib/main.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/main.js","../node_modules/@stdlib/array-uint8/lib/polyfill.js","../node_modules/@stdlib/array-uint8/lib/index.js","../node_modules/@stdlib/array-uint8/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8clampedarray/lib/main.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/main.js","../node_modules/@stdlib/array-uint8c/lib/polyfill.js","../node_modules/@stdlib/array-uint8c/lib/index.js","../node_modules/@stdlib/array-uint8c/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/index.js","../node_modules/@stdlib/assert-is-int16array/lib/main.js","../node_modules/@stdlib/assert-has-int16array-support/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/main.js","../node_modules/@stdlib/constants-int16-min/lib/index.js","../node_modules/@stdlib/array-int16/lib/polyfill.js","../node_modules/@stdlib/array-int16/lib/index.js","../node_modules/@stdlib/array-int16/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint16array/lib/main.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/main.js","../node_modules/@stdlib/array-uint16/lib/polyfill.js","../node_modules/@stdlib/array-uint16/lib/index.js","../node_modules/@stdlib/array-uint16/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/index.js","../node_modules/@stdlib/assert-is-int32array/lib/main.js","../node_modules/@stdlib/assert-has-int32array-support/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/main.js","../node_modules/@stdlib/constants-int32-min/lib/index.js","../node_modules/@stdlib/array-int32/lib/polyfill.js","../node_modules/@stdlib/array-int32/lib/index.js","../node_modules/@stdlib/array-int32/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint32array/lib/main.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/main.js","../node_modules/@stdlib/array-uint32/lib/polyfill.js","../node_modules/@stdlib/array-uint32/lib/index.js","../node_modules/@stdlib/array-uint32/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float32array/lib/main.js","../node_modules/@stdlib/assert-has-float32array-support/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/main.js","../node_modules/@stdlib/array-float32/lib/polyfill.js","../node_modules/@stdlib/array-float32/lib/index.js","../node_modules/@stdlib/array-float32/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float64array/lib/main.js","../node_modules/@stdlib/assert-has-float64array-support/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/main.js","../node_modules/@stdlib/array-float64/lib/polyfill.js","../node_modules/@stdlib/array-float64/lib/index.js","../node_modules/@stdlib/array-float64/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/index.js","../node_modules/@stdlib/utils-copy/lib/typed_arrays.js","../node_modules/@stdlib/utils-copy/lib/deep_copy.js","../node_modules/@stdlib/utils-copy/lib/copy.js","../node_modules/@stdlib/utils-copy/lib/index.js","../node_modules/@stdlib/assert-is-object/lib/main.js","../node_modules/@stdlib/assert-is-plain-object/lib/main.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/validate.js","../node_modules/@stdlib/assert-is-plain-object/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/factory.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\nvar main = ( typeof Object.defineProperty === 'function' ) ? Object.defineProperty : null;\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar defineProperty = require( './define_property.js' );\n\n\n// MAIN //\n\n/**\n* Tests for `Object.defineProperty` support.\n*\n* @private\n* @returns {boolean} boolean indicating if an environment has `Object.defineProperty` support\n*\n* @example\n* var bool = hasDefinePropertySupport();\n* // returns \n*/\nfunction hasDefinePropertySupport() {\n\t// Test basic support...\n\ttry {\n\t\tdefineProperty( {}, 'x', {} );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasDefinePropertySupport;\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// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @name defineProperty\n* @type {Function}\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nvar defineProperty = Object.defineProperty;\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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/* eslint-disable no-underscore-dangle, no-proto */\n\n'use strict';\n\n// VARIABLES //\n\nvar objectProtoype = Object.prototype;\nvar toStr = objectProtoype.toString;\nvar defineGetter = objectProtoype.__defineGetter__;\nvar defineSetter = objectProtoype.__defineSetter__;\nvar lookupGetter = objectProtoype.__lookupGetter__;\nvar lookupSetter = objectProtoype.__lookupSetter__;\n\n\n// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @param {Object} obj - object on which to define the property\n* @param {string} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nfunction defineProperty( obj, prop, descriptor ) {\n\tvar prototype;\n\tvar hasValue;\n\tvar hasGet;\n\tvar hasSet;\n\n\tif ( typeof obj !== 'object' || obj === null || toStr.call( obj ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an object. Value: `' + obj + '`.' );\n\t}\n\tif ( typeof descriptor !== 'object' || descriptor === null || toStr.call( descriptor ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. Property descriptor must be an object. Value: `' + descriptor + '`.' );\n\t}\n\thasValue = ( 'value' in descriptor );\n\tif ( hasValue ) {\n\t\tif (\n\t\t\tlookupGetter.call( obj, prop ) ||\n\t\t\tlookupSetter.call( obj, prop )\n\t\t) {\n\t\t\t// Override `__proto__` to avoid touching inherited accessors:\n\t\t\tprototype = obj.__proto__;\n\t\t\tobj.__proto__ = objectProtoype;\n\n\t\t\t// Delete property as existing getters/setters prevent assigning value to specified property:\n\t\t\tdelete obj[ prop ];\n\t\t\tobj[ prop ] = descriptor.value;\n\n\t\t\t// Restore original prototype:\n\t\t\tobj.__proto__ = prototype;\n\t\t} else {\n\t\t\tobj[ prop ] = descriptor.value;\n\t\t}\n\t}\n\thasGet = ( 'get' in descriptor );\n\thasSet = ( 'set' in descriptor );\n\n\tif ( hasValue && ( hasGet || hasSet ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.' );\n\t}\n\n\tif ( hasGet && defineGetter ) {\n\t\tdefineGetter.call( obj, prop, descriptor.get );\n\t}\n\tif ( hasSet && defineSetter ) {\n\t\tdefineSetter.call( obj, prop, descriptor.set );\n\t}\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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* Define (or modify) an object property.\n*\n* @module @stdlib/utils-define-property\n*\n* @example\n* var defineProperty = require( '@stdlib/utils-define-property' );\n*\n* var obj = {};\n* defineProperty( obj, 'foo', {\n* 'value': 'bar',\n* 'writable': false,\n* 'configurable': false,\n* 'enumerable': false\n* });\n* obj.foo = 'boop'; // => throws\n*/\n\n// MODULES //\n\nvar hasDefinePropertySupport = require( './has_define_property_support.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar defineProperty;\nif ( hasDefinePropertySupport() ) {\n\tdefineProperty = builtin;\n} else {\n\tdefineProperty = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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\nvar defineProperty = require( '@stdlib/utils-define-property' );\n\n\n// MAIN //\n\n/**\n* Defines a non-enumerable read-only property.\n*\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setNonEnumerableReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Define a non-enumerable read-only property.\n*\n* @module @stdlib/utils-define-nonenumerable-read-only-property\n*\n* @example\n* var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\n*\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\n\n// MODULES //\n\nvar setNonEnumerableReadOnly = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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// MAIN //\n\n/**\n* Tests for native `Symbol` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Symbol` support\n*\n* @example\n* var bool = hasSymbolSupport();\n* // returns \n*/\nfunction hasSymbolSupport() {\n\treturn (\n\t\ttypeof Symbol === 'function' &&\n\t\ttypeof Symbol( 'foo' ) === 'symbol'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasSymbolSupport;\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\nvar hasSymbols = require( '@stdlib/assert-has-symbol-support' );\n\n\n// VARIABLES //\n\nvar FLG = hasSymbols();\n\n\n// MAIN //\n\n/**\n* Tests for native `toStringTag` support.\n*\n* @returns {boolean} boolean indicating if an environment has `toStringTag` support\n*\n* @example\n* var bool = hasToStringTagSupport();\n* // returns \n*/\nfunction hasToStringTagSupport() {\n\treturn ( FLG && typeof Symbol.toStringTag === 'symbol' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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* Test for native `toStringTag` support.\n*\n* @module @stdlib/assert-has-tostringtag-support\n*\n* @example\n* var hasToStringTagSupport = require( '@stdlib/assert-has-tostringtag-support' );\n*\n* var bool = hasToStringTagSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasToStringTagSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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// MAIN //\n\nvar toStr = Object.prototype.toString;\n\n\n// EXPORTS //\n\nmodule.exports = toStr;\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\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification (via the internal property `[[Class]]`) of an object.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\treturn toStr.call( v );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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// FUNCTIONS //\n\nvar has = Object.prototype.hasOwnProperty;\n\n\n// MAIN //\n\n/**\n* Tests if an object has a specified property.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object has a specified property\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'bap' );\n* // returns false\n*/\nfunction hasOwnProp( value, property ) {\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\treturn has.call( value, property );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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* Test whether an object has a specified property.\n*\n* @module @stdlib/assert-has-own-property\n*\n* @example\n* var hasOwnProp = require( '@stdlib/assert-has-own-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* bool = hasOwnProp( beep, 'bop' );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasOwnProp = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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// MAIN //\n\nvar toStrTag = ( typeof Symbol === 'function' ) ? Symbol.toStringTag : '';\n\n\n// EXPORTS //\n\nmodule.exports = toStrTag;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar toStringTag = require( './tostringtag.js' );\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification of an object in environments supporting `Symbol.toStringTag`.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\tvar isOwn;\n\tvar tag;\n\tvar out;\n\n\tif ( v === null || v === void 0 ) {\n\t\treturn toStr.call( v );\n\t}\n\ttag = v[ toStringTag ];\n\tisOwn = hasOwnProp( v, toStringTag );\n\n\t// Attempt to override the `toStringTag` property. For built-ins having a `Symbol.toStringTag` property (e.g., `JSON`, `Math`, etc), the `Symbol.toStringTag` property is read-only (e.g., , so we need to wrap in a `try/catch`.\n\ttry {\n\t\tv[ toStringTag ] = void 0;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn toStr.call( v );\n\t}\n\tout = toStr.call( v );\n\n\tif ( isOwn ) {\n\t\tv[ toStringTag ] = tag;\n\t} else {\n\t\tdelete v[ toStringTag ];\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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* Return a string value indicating a specification defined classification of an object.\n*\n* @module @stdlib/utils-native-class\n*\n* @example\n* var nativeClass = require( '@stdlib/utils-native-class' );\n*\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* function Beep() {\n* return this;\n* }\n* str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\n\n// MODULES //\n\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar builtin = require( './native_class.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar nativeClass;\nif ( hasToStringTag() ) {\n\tnativeClass = polyfill;\n} else {\n\tnativeClass = builtin;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to extract a string value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a string can be extracted\n*/\nfunction test( value ) {\n\ttry {\n\t\tvalueOf.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar valueOf = String.prototype.valueOf; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2valueof.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string object\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns false\n*/\nfunction isString( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof String ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object String]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a string\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*/\nfunction isString( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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* Test if a value is a string.\n*\n* @module @stdlib/assert-is-string\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' );\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 5 );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isObject;\n*\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 'beep' );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isString = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isString, 'isPrimitive', isPrimitive );\nsetReadOnly( isString, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// VARIABLES //\n\nvar RE_CHARS = /[-\\/\\\\^$*+?.()|[\\]{}]/g; // eslint-disable-line no-useless-escape\n\n\n// MAIN //\n\n/**\n* Escapes a regular expression string.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} first argument must be a string primitive\n* @returns {string} escaped string\n*\n* @example\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\nfunction rescape( str ) {\n\tvar len;\n\tvar s;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Check if the string starts with a forward slash...\n\tif ( str[ 0 ] === '/' ) {\n\t\t// Find the last forward slash...\n\t\tlen = str.length;\n\t\tfor ( i = len-1; i >= 0; i-- ) {\n\t\t\tif ( str[ i ] === '/' ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:\n\tif ( i === void 0 || i <= 0 ) {\n\t\treturn str.replace( RE_CHARS, '\\\\$&' );\n\t}\n\t// We need to de-construct the string...\n\ts = str.substring( 1, i );\n\n\t// Only escape the characters between the `/`:\n\ts = s.replace( RE_CHARS, '\\\\$&' );\n\n\t// Reassemble:\n\tstr = str[ 0 ] + s + str.substring( i );\n\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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* Escape a regular expression string or pattern.\n*\n* @module @stdlib/utils-escape-regexp-string\n*\n* @example\n* var rescape = require( '@stdlib/utils-escape-regexp-string' );\n*\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\n\n// MODULES //\n\nvar rescape = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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\nvar RE = /./;\n\n\n// EXPORTS //\n\nmodule.exports = RE;\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* Tests if a value is a boolean primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean primitive\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns false\n*/\nfunction isBoolean( value ) {\n\treturn ( typeof value === 'boolean' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Boolean.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean object\n*\n* @example\n* var bool = isBoolean( true );\n* // returns false\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Boolean ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Boolean]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a boolean\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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* Test if a value is a boolean.\n*\n* @module @stdlib/assert-is-boolean\n*\n* @example\n* var isBoolean = require( '@stdlib/assert-is-boolean' );\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* // Use interface to check for boolean primitives...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( true ) );\n* // returns false\n*\n* @example\n* // Use interface to check for boolean objects...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isObject;\n*\n* var bool = isBoolean( true );\n* // returns false\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isBoolean = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isBoolean, 'isPrimitive', isPrimitive );\nsetReadOnly( isBoolean, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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// MAIN //\n\n/**\n* Returns the global object using code generation.\n*\n* @private\n* @returns {Object} global object\n*/\nfunction getGlobal() {\n\treturn new Function( 'return this;' )(); // eslint-disable-line no-new-func\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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// MAIN //\n\nvar obj = ( typeof self === 'object' ) ? self : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof window === 'object' ) ? window : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof global === 'object' ) ? global : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar getThis = require( './codegen.js' );\nvar Self = require( './self.js' );\nvar Win = require( './window.js' );\nvar Global = require( './global.js' );\n\n\n// MAIN //\n\n/**\n* Returns the global object.\n*\n* ## Notes\n*\n* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.\n*\n* @param {boolean} [codegen=false] - boolean indicating whether to use code generation to resolve the global object\n* @throws {TypeError} must provide a boolean\n* @throws {Error} unable to resolve global object\n* @returns {Object} global object\n*\n* @example\n* var g = getGlobal();\n* // returns {...}\n*/\nfunction getGlobal( codegen ) {\n\tif ( arguments.length ) {\n\t\tif ( !isBoolean( codegen ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Must provide a boolean primitive. Value: `'+codegen+'`.' );\n\t\t}\n\t\tif ( codegen ) {\n\t\t\treturn getThis();\n\t\t}\n\t\t// Fall through...\n\t}\n\t// Case: browsers and web workers\n\tif ( Self ) {\n\t\treturn Self;\n\t}\n\t// Case: browsers\n\tif ( Win ) {\n\t\treturn Win;\n\t}\n\t// Case: Node.js\n\tif ( Global ) {\n\t\treturn Global;\n\t}\n\t// Case: unknown\n\tthrow new Error( 'unexpected error. Unable to resolve global object.' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar getGlobal = require( '@stdlib/utils-global' );\n\n\n// MAIN //\n\nvar root = getGlobal();\nvar nodeList = root.document && root.document.childNodes;\n\n\n// EXPORTS //\n\nmodule.exports = nodeList;\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* Return the global object.\n*\n* @module @stdlib/utils-global\n*\n* @example\n* var getGlobal = require( '@stdlib/utils-global' );\n*\n* var g = getGlobal();\n* // returns {...}\n*/\n\n// MODULES //\n\nvar getGlobal = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar typedarray = Int8Array; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = typedarray;\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\nvar RE = require( './fixtures/re.js' );\nvar nodeList = require( './fixtures/nodelist.js' );\nvar typedarray = require( './fixtures/typedarray.js' );\n\n\n// MAIN //\n\n/**\n* Checks whether a polyfill is needed when using the `typeof` operator.\n*\n* @private\n* @returns {boolean} boolean indicating whether a polyfill is needed\n*/\nfunction check() {\n\tif (\n\t\t// Chrome 1-12 returns 'function' for regular expression instances (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof):\n\t\ttypeof RE === 'function' ||\n\n\t\t// Safari 8 returns 'object' for typed array and weak map constructors (underscore #1929):\n\t\ttypeof typedarray === 'object' ||\n\n\t\t// PhantomJS 1.9 returns 'function' for `NodeList` instances (underscore #2236):\n\t\ttypeof nodeList === 'function'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\nfunction reFunctionName() {\n\treturn /^\\s*function\\s*([^(]*)/i;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @module @stdlib/regexp-function-name\n*\n* @example\n* var reFunctionName = require( '@stdlib/regexp-function-name' );\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reFunctionName = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reFunctionName, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\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\nvar reFunctionName = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Captures everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* Regular expression: `/^\\s*function\\s*([^(]*)/i`\n*\n* - `/^\\s*`\n* - Match zero or more spaces at beginning\n*\n* - `function`\n* - Match the word `function`\n*\n* - `\\s*`\n* - Match zero or more spaces after the word `function`\n*\n* - `()`\n* - Capture\n*\n* - `[^(]*`\n* - Match anything except a left parenthesis `(` zero or more times\n*\n* - `/i`\n* - ignore case\n*\n* @constant\n* @type {RegExp}\n* @default /^\\s*function\\s*([^(]*)/i\n*/\nvar RE_FUNCTION_NAME = reFunctionName();\n\n\n// EXPORTS //\n\nmodule.exports = RE_FUNCTION_NAME;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar f;\n\n\n// FUNCTIONS //\n\n/**\n* Tests if a value is an array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an array\n*\n* @example\n* var bool = isArray( [] );\n* // returns true\n*\n* @example\n* var bool = isArray( {} );\n* // returns false\n*/\nfunction isArray( value ) {\n\treturn ( nativeClass( value ) === '[object Array]' );\n}\n\n\n// MAIN //\n\nif ( Array.isArray ) {\n\tf = Array.isArray;\n} else {\n\tf = isArray;\n}\n\n\n// EXPORTS //\n\nmodule.exports = f;\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* Test if a value is an array.\n*\n* @module @stdlib/assert-is-array\n*\n* @example\n* var isArray = require( '@stdlib/assert-is-array' );\n*\n* var bool = isArray( [] );\n* // returns true\n*\n* bool = isArray( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isArray = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isArray;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Returns a function which tests if every element in an array passes a test condition.\n*\n* @param {Function} predicate - function to apply\n* @throws {TypeError} must provide a function\n* @returns {Function} an array function\n*\n* @example\n* var isOdd = require( '@stdlib/assert-is-odd' );\n*\n* var arr1 = [ 1, 3, 5, 7 ];\n* var arr2 = [ 3, 5, 8 ];\n*\n* var validate = arrayfcn( isOdd );\n*\n* var bool = validate( arr1 );\n* // returns true\n*\n* bool = validate( arr2 );\n* // returns false\n*/\nfunction arrayfcn( predicate ) {\n\tif ( typeof predicate !== 'function' ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a function. Value: `' + predicate + '`.' );\n\t}\n\treturn every;\n\n\t/**\n\t* Tests if every element in an array passes a test condition.\n\t*\n\t* @private\n\t* @param {*} value - value to test\n\t* @returns {boolean} boolean indicating whether a value is an array for which all elements pass a test condition\n\t*/\n\tfunction every( value ) {\n\t\tvar len;\n\t\tvar i;\n\t\tif ( !isArray( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tlen = value.length;\n\t\tif ( len === 0 ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( predicate( value[ i ] ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayfcn;\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* Tests if a value is object-like.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is object-like\n*\n* @example\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( [] );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( null );\n* // returns false\n*/\nfunction isObjectLike( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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* Test if a value is object-like.\n*\n* @module @stdlib/assert-is-object-like\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' );\n*\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* bool = isObjectLike( [] );\n* // returns true\n*\n* bool = isObjectLike( null );\n* // returns false\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' ).isObjectLikeArray;\n*\n* var bool = isObjectLike( [ {}, [] ] );\n* // returns true\n*\n* bool = isObjectLike( [ {}, '3.0' ] );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar arrayfun = require( '@stdlib/assert-tools-array-function' );\nvar isObjectLike = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( isObjectLike, 'isObjectLikeArray', arrayfun( isObjectLike ) );\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Buffer instance.\n*\n* @param {*} value - value to validate\n* @returns {boolean} boolean indicating if a value is a Buffer instance\n*\n* @example\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( new Buffer( [1,2,3,4] ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( {} );\n* // returns false\n*\n* @example\n* var v = isBuffer( [] );\n* // returns false\n*/\nfunction isBuffer( value ) {\n\treturn (\n\t\tisObjectLike( value ) &&\n\t\t(\n\t\t\t// eslint-disable-next-line no-underscore-dangle\n\t\t\tvalue._isBuffer || // for envs missing Object.prototype.constructor (e.g., Safari 5-7)\n\t\t\t(\n\t\t\t\tvalue.constructor &&\n\n\t\t\t\t// WARNING: `typeof` is not a foolproof check, as certain envs consider RegExp and NodeList instances to be functions\n\t\t\t\ttypeof value.constructor.isBuffer === 'function' &&\n\t\t\t\tvalue.constructor.isBuffer( value )\n\t\t\t)\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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* Test if a value is a Buffer instance.\n*\n* @module @stdlib/assert-is-buffer\n*\n* @example\n* var isBuffer = require( '@stdlib/assert-is-buffer' );\n*\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* v = isBuffer( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isBuffer = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar RE = require( '@stdlib/regexp-function-name' ).REGEXP;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\n\n\n// MAIN //\n\n/**\n* Determines the name of a value's constructor.\n*\n* @param {*} v - input value\n* @returns {string} name of a value's constructor\n*\n* @example\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* @example\n* var v = constructorName( 5 );\n* // returns 'Number'\n*\n* @example\n* var v = constructorName( null );\n* // returns 'Null'\n*\n* @example\n* var v = constructorName( undefined );\n* // returns 'Undefined'\n*\n* @example\n* var v = constructorName( function noop() {} );\n* // returns 'Function'\n*/\nfunction constructorName( v ) {\n\tvar match;\n\tvar name;\n\tvar ctor;\n\tname = nativeClass( v ).slice( 8, -1 );\n\tif ( (name === 'Object' || name === 'Error') && v.constructor ) {\n\t\tctor = v.constructor;\n\t\tif ( typeof ctor.name === 'string' ) {\n\t\t\treturn ctor.name;\n\t\t}\n\t\tmatch = RE.exec( ctor.toString() );\n\t\tif ( match ) {\n\t\t\treturn match[ 1 ];\n\t\t}\n\t}\n\tif ( isBuffer( v ) ) {\n\t\treturn 'Buffer';\n\t}\n\treturn name;\n}\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// NOTES //\n\n/*\n* Built-in `typeof` operator behavior:\n*\n* ```text\n* typeof null => 'object'\n* typeof undefined => 'undefined'\n* typeof 'a' => 'string'\n* typeof 5 => 'number'\n* typeof NaN => 'number'\n* typeof true => 'boolean'\n* typeof false => 'boolean'\n* typeof {} => 'object'\n* typeof [] => 'object'\n* typeof function foo(){} => 'function'\n* typeof function* foo(){} => 'object'\n* typeof Symbol() => 'symbol'\n* ```\n*\n*/\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\tvar type;\n\n\t// Address `typeof null` => `object` (see http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null):\n\tif ( v === null ) {\n\t\treturn 'null';\n\t}\n\ttype = typeof v;\n\n\t// If the `typeof` operator returned something other than `object`, we are done. Otherwise, we need to check for an internal class name or search for a constructor.\n\tif ( type === 'object' ) {\n\t\treturn ctorName( v ).toLowerCase();\n\t}\n\treturn type;\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine the name of a value's constructor.\n*\n* @module @stdlib/utils-constructor-name\n*\n* @example\n* var constructorName = require( '@stdlib/utils-constructor-name' );\n*\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* v = constructorName( {} );\n* // returns 'Object'\n*\n* v = constructorName( true );\n* // returns 'Boolean'\n*/\n\n// MODULES //\n\nvar constructorName = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\treturn ctorName( v ).toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine a value's type.\n*\n* @module @stdlib/utils-type-of\n*\n* @example\n* var typeOf = require( '@stdlib/utils-type-of' );\n*\n* var str = typeOf( 'a' );\n* // returns 'string'\n*\n* str = typeOf( 5 );\n* // returns 'number'\n*/\n\n// MODULES //\n\nvar usePolyfill = require( './check.js' );\nvar typeOf = require( './typeof.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main = ( usePolyfill() ) ? polyfill : typeOf;\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar typeOf = require( '@stdlib/utils-type-of' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a function.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a function\n*\n* @example\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\nfunction isFunction( value ) {\n\t// Note: cannot use `typeof` directly, as various browser engines incorrectly return `'function'` when operating on non-function objects, such as regular expressions and NodeLists.\n\treturn ( typeOf( value ) === 'function' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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* Test if a value is a function.\n*\n* @module @stdlib/assert-is-function\n*\n* @example\n* var isFunction = require( '@stdlib/assert-is-function' );\n*\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\n\n// MODULES //\n\nvar isFunction = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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\nvar exec = require( './exec.js' );\n\n\n// MAIN //\n\n/**\n* Attempts to call a `RegExp` method.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if able to call a `RegExp` method\n*/\nfunction test( value ) {\n\ttry {\n\t\texec.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar exec = RegExp.prototype.exec; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = exec;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2exec.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a regular expression.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a regular expression\n*\n* @example\n* var bool = isRegExp( /\\.+/ );\n* // returns true\n*\n* @example\n* var bool = isRegExp( {} );\n* // returns false\n*/\nfunction isRegExp( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof RegExp ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object RegExp]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isRegExp;\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\nvar rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument argument must be a string primitive or regular expression\n* @throws {TypeError} third argument must be a string primitive or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive or regular expression. Value: `' + search + '`.' );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( 'invalid argument. Third argument must be a string primitive or replacement function. Value: `' + newval + '`.' );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Constructor which returns a `Number` object.\n*\n* @module @stdlib/number-ctor\n*\n* @example\n* var Number = require( '@stdlib/number-ctor' );\n*\n* var v = new Number( 10.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar Number = require( './number.js' );\n\n\n// EXPORTS //\n\nmodule.exports = Number;\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// EXPORTS //\n\nmodule.exports = Number; // eslint-disable-line stdlib/require-globals\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Number.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar Number = require( '@stdlib/number-ctor' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\nfunction isNumber( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Number ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Number]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a number\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( null );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Test if a value is a number.\n*\n* @module @stdlib/assert-is-number\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' );\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( null );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isObject;\n*\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNumber, 'isPrimitive', isPrimitive );\nsetReadOnly( isNumber, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Double-precision floating-point positive infinity.\n*\n* @module @stdlib/constants-float64-pinf\n* @type {number}\n*\n* @example\n* var FLOAT64_PINF = require( '@stdlib/constants-float64-pinf' );\n* // returns Infinity\n*/\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point positive infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point positive infinity has the bit sequence\n*\n* ```binarystring\n* 0 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.POSITIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_PINF = Number.POSITIVE_INFINITY; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_PINF;\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* Double-precision floating-point negative infinity.\n*\n* @module @stdlib/constants-float64-ninf\n* @type {number}\n*\n* @example\n* var FLOAT64_NINF = require( '@stdlib/constants-float64-ninf' );\n* // returns -Infinity\n*/\n\n// MODULES //\n\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point negative infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point negative infinity has the bit sequence\n*\n* ```binarystring\n* 1 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.NEGATIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_NINF = Number.NEGATIVE_INFINITY;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_NINF;\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\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Tests if a finite double-precision floating-point number is an integer.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\treturn (floor(x) === x);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// TODO: implementation (?)\n\n/**\n* Rounds a double-precision floating-point number toward negative infinity.\n*\n* @param {number} x - input value\n* @returns {number} rounded value\n*\n* @example\n* var v = floor( -4.2 );\n* // returns -5.0\n*\n* @example\n* var v = floor( 9.99999 );\n* // returns 9.0\n*\n* @example\n* var v = floor( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = floor( NaN );\n* // returns NaN\n*/\nvar floor = Math.floor; // eslint-disable-line stdlib/no-builtin-math\n\n\n// EXPORTS //\n\nmodule.exports = floor;\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* Test if a finite double-precision floating-point number is an integer.\n*\n* @module @stdlib/math-base-assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/math-base-assert-is-integer' );\n*\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* bool = isInteger( 3.14 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isInteger = require( './is_integer.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar isInt = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests if a number primitive is an integer value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a number primitive is an integer value\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tvalue < PINF &&\n\t\tvalue > NINF &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having an integer value\n*\n* @example\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having an integer value\n*\n* @example\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an integer\n*\n* @example\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isInteger( -3.14 );\n* // returns false\n*\n* @example\n* var bool = isInteger( null );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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* Test if a value is an integer.\n*\n* @module @stdlib/assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/assert-is-integer' );\n*\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isInteger( -3.14 );\n* // returns false\n*\n* bool = isInteger( null );\n* // returns false\n*\n* @example\n* // Use interface to check for integer primitives...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n*\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*\n* @example\n* // Use interface to check for integer objects...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n*\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue.valueOf() >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a nonnegative integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a nonnegative integer\n*\n* @example\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( null );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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* Test if a value is a nonnegative integer.\n*\n* @module @stdlib/assert-is-nonnegative-integer\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' );\n*\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* bool = isNonNegativeInteger( null );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isObject;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNonNegativeInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isNonNegativeInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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// MAIN //\n\nvar getProto = Object.getPrototypeOf;\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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* Returns the value of the `__proto__` property.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {*} value of `__proto__` property\n*/\nfunction getProto( obj ) {\n\t// eslint-disable-next-line no-proto\n\treturn obj.__proto__;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar getProto = require( './proto.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {(Object|null)} prototype\n*/\nfunction getPrototypeOf( obj ) {\n\tvar proto = getProto( obj );\n\tif ( proto || proto === null ) {\n\t\treturn proto;\n\t}\n\tif ( nativeClass( obj.constructor ) === '[object Function]' ) {\n\t\t// May break if the constructor has been tampered with...\n\t\treturn obj.constructor.prototype;\n\t}\n\tif ( obj instanceof Object ) {\n\t\treturn Object.prototype;\n\t}\n\t// Return `null` for objects created via `Object.create( null )`. Also return `null` for cross-realm objects on browsers that lack `__proto__` support, such as IE < 11.\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar builtin = require( './native.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar getProto;\nif ( isFunction( Object.getPrototypeOf ) ) {\n\tgetProto = builtin;\n} else {\n\tgetProto = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar getProto = require( './detect.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @param {*} value - input value\n* @returns {(Object|null)} prototype\n*\n* @example\n* var proto = getPrototypeOf( {} );\n* // returns {}\n*/\nfunction getPrototypeOf( value ) {\n\tif (\n\t\tvalue === null ||\n\t\tvalue === void 0\n\t) {\n\t\treturn null;\n\t}\n\t// In order to ensure consistent ES5/ES6 behavior, cast input value to an object (strings, numbers, booleans); ES5 `Object.getPrototypeOf` throws when provided primitives and ES6 `Object.getPrototypeOf` casts:\n\tvalue = Object( value );\n\n\treturn getProto( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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* Return the prototype of a provided object.\n*\n* @module @stdlib/utils-get-prototype-of\n*\n* @example\n* var getPrototype = require( '@stdlib/utils-get-prototype-of' );\n*\n* var proto = getPrototype( {} );\n* // returns {}\n*/\n\n// MODULES //\n\nvar getPrototype = require( './get_prototype_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getPrototype;\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\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an `Error` object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `Error` object\n*\n* @example\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isError( {} );\n* // returns false\n*/\nfunction isError( value ) {\n\tif ( typeof value !== 'object' || value === null ) {\n\t\treturn false;\n\t}\n\t// Check for `Error` objects from the same realm (same Node.js `vm` or same `Window` object)...\n\tif ( value instanceof Error ) {\n\t\treturn true;\n\t}\n\t// Walk the prototype tree until we find an object having the desired native class...\n\twhile ( value ) {\n\t\tif ( nativeClass( value ) === '[object Error]' ) {\n\t\t\treturn true;\n\t\t}\n\t\tvalue = getPrototypeOf( value );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isError;\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* Test if a value is an `Error` object.\n*\n* @module @stdlib/assert-is-error\n*\n* @example\n* var isError = require( '@stdlib/assert-is-error' );\n*\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* bool = isError( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isError = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isError;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to parse a regular expression string.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*/\nfunction reRegExp() {\n\treturn /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/; // eslint-disable-line no-useless-escape\n}\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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* Return a regular expression to parse a regular expression string.\n*\n* @module @stdlib/regexp-regexp\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var parts = RE_REGEXP.exec( '/^.*$/ig' );\n* // returns [ '/^.*$/ig', '^.*$', 'ig', 'index': 0, 'input': '/^.*$/ig' ]\n*/\n\n// MAIN //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reRegExp = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reRegExp, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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\nvar reRegExp = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Matches parts of a regular expression string.\n*\n* Regular expression: `/^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/`\n*\n* - `/^\\/`\n* - match a string that begins with a `/`\n*\n* - `()`\n* - capture\n*\n* - `(?:)+`\n* - capture, but do not remember, a group of characters which occur one or more times\n*\n* - `\\\\\\/`\n* - match the literal `\\/`\n*\n* - `|`\n* - OR\n*\n* - `[^\\/]`\n* - anything which is not the literal `\\/`\n*\n* - `\\/`\n* - match the literal `/`\n*\n* - `([imgy]*)`\n* - capture any characters matching `imgy` occurring zero or more times\n*\n* - `$/`\n* - string end\n*\n*\n* @constant\n* @type {RegExp}\n* @default /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/\n*/\nvar RE_REGEXP = reRegExp();\n\n\n// EXPORTS //\n\nmodule.exports = RE_REGEXP;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar reRegExp = require( '@stdlib/regexp-regexp' );\n\n\n// MAIN //\n\n/**\n* Parses a regular expression string and returns a new regular expression.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} must provide a regular expression string\n* @returns {(RegExp|null)} regular expression or null\n*\n* @example\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\nfunction reFromString( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Capture the regular expression pattern and any flags:\n\tstr = reRegExp().exec( str );\n\n\t// Create a new regular expression:\n\treturn ( str ) ? new RegExp( str[1], str[2] ) : null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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* Create a regular expression from a regular expression string.\n*\n* @module @stdlib/utils-regexp-from-string\n*\n* @example\n* var reFromString = require( '@stdlib/utils-regexp-from-string' );\n*\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\n\n// MODULES //\n\nvar reFromString = require( './from_string.js' );\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is `NaN`.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 7.0 );\n* // returns false\n*/\nfunction isnan( x ) {\n\treturn ( x !== x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a `NaN` number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a `NaN` number primitive\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a double-precision floating-point numeric value is `NaN`.\n*\n* @module @stdlib/math-base-assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/math-base-assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 7.0 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isnan = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a value of `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a value of `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( null );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a value is `NaN`.\n*\n* @module @stdlib/assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( null );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isObject;\n*\n* var bool = isnan( NaN );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isnan = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isnan, 'isPrimitive', isPrimitive );\nsetReadOnly( isnan, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a collection.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is a collection\n*\n* @example\n* var bool = isCollection( [] );\n* // returns true\n*\n* @example\n* var bool = isCollection( {} );\n* // returns false\n*/\nfunction isCollection( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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\nvar isnan = require( '@stdlib/assert-is-nan' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Returns the first index at which a given element can be found.\n*\n* @param {ArrayLike} arr - array-like object\n* @param {*} searchElement - element to find\n* @param {integer} [fromIndex] - starting index (if negative, the start index is determined relative to last element)\n* @throws {TypeError} must provide an array-like object\n* @throws {TypeError} `fromIndex` must be an integer\n* @returns {integer} index or -1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 5 );\n* // returns -1\n*\n* @example\n* // Using a `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* @example\n* // `fromIndex` which exceeds `array` length:\n* var arr = [ 1, 2, 3, 4, 2, 5 ];\n* var idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* @example\n* // Negative `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* var idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* @example\n* // Negative `fromIndex` exceeding input `array` length:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* @example\n* // Array-like objects:\n* var str = 'bebop';\n* var idx = indexOf( str, 'o' );\n* // returns 3\n*/\nfunction indexOf( arr, searchElement, fromIndex ) {\n\tvar len;\n\tvar i;\n\tif ( !isCollection( arr ) && !isString( arr ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array-like object. Value: `' + arr + '`.' );\n\t}\n\tlen = arr.length;\n\tif ( len === 0 ) {\n\t\treturn -1;\n\t}\n\tif ( arguments.length === 3 ) {\n\t\tif ( !isInteger( fromIndex ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `fromIndex` must be an integer. Value: `' + fromIndex + '`.' );\n\t\t}\n\t\tif ( fromIndex >= 0 ) {\n\t\t\tif ( fromIndex >= len ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\ti = fromIndex;\n\t\t} else {\n\t\t\ti = len + fromIndex;\n\t\t\tif ( i < 0 ) {\n\t\t\t\ti = 0;\n\t\t\t}\n\t\t}\n\t} else {\n\t\ti = 0;\n\t}\n\t// Check for `NaN`...\n\tif ( isnan( searchElement ) ) {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( isnan( arr[i] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( arr[ i ] === searchElement ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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* Maximum length of a typed array.\n*\n* @module @stdlib/constants-array-max-typed-array-length\n*\n* @example\n* var MAX_TYPED_ARRAY_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n* // returns 9007199254740991\n*/\n\n// MAIN //\n\n/**\n* Maximum length of a typed array.\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n*/\nvar MAX_TYPED_ARRAY_LENGTH = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = MAX_TYPED_ARRAY_LENGTH;\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* Return the first index at which a given element can be found.\n*\n* @module @stdlib/utils-index-of\n*\n* @example\n* var indexOf = require( '@stdlib/utils-index-of' );\n*\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* arr = [ 4, 3, 2, 1 ];\n* idx = indexOf( arr, 5 );\n* // returns -1\n*\n* // Using a `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* // `fromIndex` which exceeds `array` length:\n* arr = [ 1, 2, 3, 4, 2, 5 ];\n* idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* // Negative `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* // Negative `fromIndex` exceeding input `array` length:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* // Array-like objects:\n* var str = 'bebop';\n* idx = indexOf( str, 'o' );\n* // returns 3\n*/\n\n// MODULES //\n\nvar indexOf = require( './index_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.keys()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\treturn Object.keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar keys = require( './builtin.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests the built-in `Object.keys()` implementation when provided `arguments`.\n*\n* @private\n* @returns {boolean} boolean indicating whether the built-in implementation returns the expected number of keys\n*/\nfunction test() {\n\treturn ( keys( arguments ) || '' ).length !== 2;\n}\n\n\n// MAIN //\n\n/**\n* Tests whether the built-in `Object.keys()` implementation supports providing `arguments` as an input value.\n*\n* ## Notes\n*\n* - Safari 5.0 does **not** support `arguments` as an input value.\n*\n* @private\n* @returns {boolean} boolean indicating whether a built-in implementation supports `arguments`\n*/\nfunction check() {\n\treturn test( 1, 2 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\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// MAIN //\n\nvar bool = ( typeof Object.keys !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn ( nativeClass( value ) === '[object Arguments]' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( './main.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment returns the expected internal class of the `arguments` object.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment behaves as expected\n*\n* @example\n* var bool = detect();\n* // returns \n*/\nfunction detect() {\n\treturn isArguments( arguments );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnum = require( './native.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment has a bug where String indices are not detected as \"enumerable\" properties. Observed in Node v0.10.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment has the bug\n*/\nfunction detect() {\n\treturn !isEnum.call( 'beep', '0' );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @private\n* @name isEnumerableProperty\n* @type {Function}\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nvar isEnumerableProperty = Object.prototype.propertyIsEnumerable;\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar isString = require( '@stdlib/assert-is-string' );\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isEnum = require( './native.js' );\nvar hasStringEnumBug = require( './has_string_enumerability_bug.js' );\n\n\n// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nfunction isEnumerableProperty( value, property ) {\n\tvar bool;\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\tbool = isEnum.call( value, property );\n\tif ( !bool && hasStringEnumBug && isString( value ) ) {\n\t\t// Note: we only check for indices, as properties attached to a `String` object are properly detected as enumerable above.\n\t\tproperty = +property;\n\t\treturn (\n\t\t\t!isnan( property ) &&\n\t\t\tisInteger( property ) &&\n\t\t\tproperty >= 0 &&\n\t\t\tproperty < value.length\n\t\t);\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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* Test whether an object's own property is enumerable.\n*\n* @module @stdlib/assert-is-enumerable-property\n*\n* @example\n* var isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\n\n// MODULES //\n\nvar isEnumerableProperty = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-uint32-max' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object' &&\n\t\t!isArray( value ) &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH &&\n\t\thasOwnProp( value, 'callee' ) &&\n\t\t!isEnumerableProperty( value, 'callee' )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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* Test if a value is an `arguments` object.\n*\n* @module @stdlib/assert-is-arguments\n*\n* @example\n* var isArguments = require( '@stdlib/assert-is-arguments' );\n*\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* bool = isArguments( [] );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasArgumentsClass = require( './detect.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar isArguments;\nif ( hasArgumentsClass ) {\n\tisArguments = main;\n} else {\n\tisArguments = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar builtin = require( './builtin.js' );\n\n\n// VARIABLES //\n\nvar slice = Array.prototype.slice;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tif ( isArguments( value ) ) {\n\t\treturn builtin( slice.call( value ) );\n\t}\n\treturn builtin( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* No operation.\n*\n* @example\n* noop();\n* // ...does nothing.\n*/\nfunction noop() {\n\t// Empty function...\n}\n\n\n// EXPORTS //\n\nmodule.exports = noop;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar noop = require( '@stdlib/utils-noop' );\n\n\n// MAIN //\n\n// Note: certain environments treat an object's prototype as enumerable, which, as a matter of convention, it shouldn't be...\nvar bool = isEnumerableProperty( noop, 'prototype' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n\n\n// VARIABLES //\n\nvar obj = {\n\t'toString': null\n};\n\n\n// MAIN //\n\n// Note: certain environments don't allow enumeration of overwritten properties which are considered non-enumerable...\nvar bool = !isEnumerableProperty( obj, 'toString' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests whether a value equals the prototype of its constructor.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction isConstructorPrototype( value ) {\n\treturn ( value.constructor && value.constructor.prototype === value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isConstructorPrototype;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar EXCLUDED_KEYS = require( './excluded_keys.json' );\nvar win = require( './window.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Determines whether an environment throws when comparing to the prototype of a value's constructor (e.g., [IE9][1]).\n*\n* [1]: https://stackoverflow.com/questions/7688070/why-is-comparing-the-constructor-property-of-two-windows-unreliable\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment is buggy\n*/\nfunction check() {\n\tvar k;\n\tif ( typeOf( win ) === 'undefined' ) {\n\t\treturn false;\n\t}\n\tfor ( k in win ) { // eslint-disable-line guard-for-in\n\t\ttry {\n\t\t\tif (\n\t\t\t\tindexOf( EXCLUDED_KEYS, k ) === -1 &&\n\t\t\t\thasOwnProp( win, k ) &&\n\t\t\t\twin[ k ] !== null &&\n\t\t\t\ttypeOf( win[ k ] ) === 'object'\n\t\t\t) {\n\t\t\t\tisConstructorPrototype( win[ k ] );\n\t\t\t}\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// MAIN //\n\nbool = check();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\nvar w = ( typeof window === 'undefined' ) ? void 0 : window;\n\n\n// EXPORTS //\n\nmodule.exports = w;\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// MAIN //\n\nvar bool = ( typeof window !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar hasAutomationEqualityBug = require( './has_automation_equality_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar HAS_WINDOW = require( './has_window.js' );\n\n\n// MAIN //\n\n/**\n* Wraps the test for constructor prototype equality to accommodate buggy environments (e.g., environments which throw when testing equality).\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction wrapper( value ) {\n\tif ( HAS_WINDOW === false && !hasAutomationEqualityBug ) {\n\t\treturn isConstructorPrototype( value );\n\t}\n\ttry {\n\t\treturn isConstructorPrototype( value );\n\t} catch ( error ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = wrapper;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar HAS_ENUM_PROTO_BUG = require( './has_enumerable_prototype_bug.js' );\nvar HAS_NON_ENUM_PROPS_BUG = require( './has_non_enumerable_properties_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype_wrapper.js' );\nvar NON_ENUMERABLE = require( './non_enumerable.json' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tvar skipConstructor;\n\tvar skipPrototype;\n\tvar isFcn;\n\tvar out;\n\tvar k;\n\tvar p;\n\tvar i;\n\n\tout = [];\n\tif ( isArguments( value ) ) {\n\t\t// Account for environments which treat `arguments` differently...\n\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\tout.push( i.toString() );\n\t\t}\n\t\t// Note: yes, we are precluding the `arguments` array-like object from having other enumerable properties; however, this should (1) be very rare and (2) not be encouraged (e.g., doing something like `arguments.a = 'b'`; in certain engines directly manipulating the `arguments` value results in automatic de-optimization).\n\t\treturn out;\n\t}\n\tif ( typeof value === 'string' ) {\n\t\t// Account for environments which do not treat string character indices as \"own\" properties...\n\t\tif ( value.length > 0 && !hasOwnProp( value, '0' ) ) {\n\t\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\t\tout.push( i.toString() );\n\t\t\t}\n\t\t}\n\t} else {\n\t\tisFcn = ( typeof value === 'function' );\n\t\tif ( isFcn === false && !isObjectLike( value ) ) {\n\t\t\treturn out;\n\t\t}\n\t\tskipPrototype = ( HAS_ENUM_PROTO_BUG && isFcn );\n\t}\n\tfor ( k in value ) {\n\t\tif ( !( skipPrototype && k === 'prototype' ) && hasOwnProp( value, k ) ) {\n\t\t\tout.push( String( k ) );\n\t\t}\n\t}\n\tif ( HAS_NON_ENUM_PROPS_BUG ) {\n\t\tskipConstructor = isConstructorPrototype( value );\n\t\tfor ( i = 0; i < NON_ENUMERABLE.length; i++ ) {\n\t\t\tp = NON_ENUMERABLE[ i ];\n\t\t\tif ( !( skipConstructor && p === 'constructor' ) && hasOwnProp( value, p ) ) {\n\t\t\t\tout.push( String( p ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar hasArgumentsBug = require( './has_arguments_bug.js' );\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar wrapper = require( './builtin_wrapper.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @name keys\n* @type {Function}\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nvar keys;\nif ( HAS_BUILTIN ) {\n\tif ( hasArgumentsBug() ) {\n\t\tkeys = wrapper;\n\t} else {\n\t\tkeys = builtin;\n\t}\n} else {\n\tkeys = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* Return an array of an object's own enumerable property names.\n*\n* @module @stdlib/utils-keys\n*\n* @example\n* var keys = require( '@stdlib/utils-keys' );\n*\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\n\n// MODULES //\n\nvar keys = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyNames !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyNames = Object.getOwnPropertyNames;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn propertyNames( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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\nvar keys = require( '@stdlib/utils-keys' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n* - In environments lacking support for `Object.getOwnPropertyNames()`, property descriptors are unavailable, and thus all properties can be safely assumed to be enumerable. Hence, we can defer to calling `Object.keys`, which retrieves all own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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* Return an array of an object's own enumerable and non-enumerable property names.\n*\n* @module @stdlib/utils-property-names\n*\n* @example\n* var getOwnPropertyNames = require( '@stdlib/utils-property-names' );\n*\n* var keys = getOwnPropertyNames({\n* 'foo': 'bar',\n* 'beep': 'boop'\n* });\n* // e.g., returns [ 'foo', 'beep' ]\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyDescriptor !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyDescriptor = Object.getOwnPropertyDescriptor;\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tvar desc;\n\tif ( value === null || value === void 0 ) {\n\t\treturn null;\n\t}\n\tdesc = propertyDescriptor( value, property );\n\treturn ( desc === void 0 ) ? null : desc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n* - In environments lacking `Object.getOwnPropertyDescriptor()` support, property descriptors do not exist. In non-supporting environment, if an object has a provided property, this function returns a descriptor object equivalent to that returned in a supporting environment; otherwise, the function returns `null`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tif ( hasOwnProp( value, property ) ) {\n\t\treturn {\n\t\t\t'configurable': true,\n\t\t\t'enumerable': true,\n\t\t\t'writable': true,\n\t\t\t'value': value[ property ]\n\t\t};\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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* Return a property descriptor for an object's own property.\n*\n* @module @stdlib/utils-property-descriptor\n*\n* @example\n* var getOwnPropertyDescriptor = require( '@stdlib/utils-property-descriptor' );\n*\n* var obj = {\n* 'foo': 'bar',\n* 'beep': 'boop'\n* };\n*\n* var keys = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':'bar'}\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// TODO: write (browser) polyfill\n\n// MAIN //\n\n/**\n* Buffer constructor.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Buffer constructor.\n*\n* @module @stdlib/buffer-ctor\n*\n* @example\n* var ctor = require( '@stdlib/buffer-ctor' );\n*\n* var b = new ctor( [ 1, 2, 3, 4 ] );\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\nvar main = require( './buffer.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasNodeBufferSupport() ) {\n\tctor = main;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = require( 'buffer' ).Buffer; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\nvar bool = isFunction( Buffer.from );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn Buffer.from( buffer );\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn new Buffer( buffer ); // eslint-disable-line no-buffer-constructor\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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* Copy buffer data to a new `Buffer` instance.\n*\n* @module @stdlib/buffer-from-buffer\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n* var copyBuffer = require( '@stdlib/buffer-from-buffer' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = copyBuffer( b1 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFrom = require( './has_from.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar copyBuffer;\nif ( hasFrom ) {\n\tcopyBuffer = main;\n} else {\n\tcopyBuffer = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt8Array = ( typeof Int8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int8Array\n*\n* @example\n* var bool = isInt8Array( new Int8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt8Array( [] );\n* // returns false\n*/\nfunction isInt8Array( value ) {\n\treturn (\n\t\t( hasInt8Array && value instanceof Int8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt8Array;\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// MAIN //\n\nvar main = ( typeof Int8Array === 'function' ) ? Int8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt8Array = require( '@stdlib/assert-is-int8array' );\nvar INT8_MAX = require( '@stdlib/constants-int8-max' );\nvar INT8_MIN = require( '@stdlib/constants-int8-min' );\nvar GlobalInt8Array = require( './int8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int8Array` support\n*\n* @example\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\nfunction hasInt8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt8Array( [ 1, 3.14, -3.14, INT8_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT8_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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* Minimum signed 8-bit integer.\n*\n* @module @stdlib/constants-int8-min\n* @type {integer32}\n*\n* @example\n* var INT8_MIN = require( '@stdlib/constants-int8-min' );\n* // returns -128\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 8-bit integer.\n*\n* ## Notes\n*\n* The number is given by\n*\n* ```tex\n* -(2^{7})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -128\n*/\nvar INT8_MIN = -128|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT8_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int8\n*\n* @example\n* var ctor = require( '@stdlib/array-int8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\nvar builtin = require( './int8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int8Array === 'function' ) ? Int8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int8Array` support.\n*\n* @module @stdlib/assert-has-int8array-support\n*\n* @example\n* var hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\n*\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8Array = ( typeof Uint8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8Array\n*\n* @example\n* var bool = isUint8Array( new Uint8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8Array( [] );\n* // returns false\n*/\nfunction isUint8Array( value ) {\n\treturn (\n\t\t( hasUint8Array && value instanceof Uint8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8Array;\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// MAIN //\n\nvar main = ( typeof Uint8Array === 'function' ) ? Uint8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8Array = require( '@stdlib/assert-is-uint8array' );\nvar UINT8_MAX = require( '@stdlib/constants-uint8-max' );\nvar GlobalUint8Array = require( './uint8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8Array` support\n*\n* @example\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\nfunction hasUint8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT8_MAX+1, UINT8_MAX+2 ];\n\t\tarr = new GlobalUint8Array( arr );\n\t\tbool = (\n\t\t\tisUint8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT8_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint8\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\nvar builtin = require( './uint8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8Array === 'function' ) ? Uint8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8Array` support.\n*\n* @module @stdlib/assert-has-uint8array-support\n*\n* @example\n* var hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\n*\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8ClampedArray = ( typeof Uint8ClampedArray === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8ClampedArray.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8ClampedArray\n*\n* @example\n* var bool = isUint8ClampedArray( new Uint8ClampedArray( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8ClampedArray( [] );\n* // returns false\n*/\nfunction isUint8ClampedArray( value ) {\n\treturn (\n\t\t( hasUint8ClampedArray && value instanceof Uint8ClampedArray ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8ClampedArray]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8ClampedArray;\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// MAIN //\n\nvar main = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8ClampedArray = require( '@stdlib/assert-is-uint8clampedarray' );\nvar GlobalUint8ClampedArray = require( './uint8clampedarray.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8ClampedArray` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8ClampedArray` support\n*\n* @example\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\nfunction hasUint8ClampedArraySupport() { // eslint-disable-line id-length\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8ClampedArray !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalUint8ClampedArray( [ -1, 0, 1, 3.14, 4.99, 255, 256 ] );\n\t\tbool = (\n\t\t\tisUint8ClampedArray( arr ) &&\n\t\t\tarr[ 0 ] === 0 && // clamped\n\t\t\tarr[ 1 ] === 0 &&\n\t\t\tarr[ 2 ] === 1 &&\n\t\t\tarr[ 3 ] === 3 && // round to nearest\n\t\t\tarr[ 4 ] === 5 && // round to nearest\n\t\t\tarr[ 5 ] === 255 &&\n\t\t\tarr[ 6 ] === 255 // clamped\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @module @stdlib/array-uint8c\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8c' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' ); // eslint-disable-line id-length\nvar builtin = require( './uint8clampedarray.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ClampedArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8ClampedArray` support.\n*\n* @module @stdlib/assert-has-uint8clampedarray-support\n*\n* @example\n* var hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' );\n*\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt16Array = ( typeof Int16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int16Array\n*\n* @example\n* var bool = isInt16Array( new Int16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt16Array( [] );\n* // returns false\n*/\nfunction isInt16Array( value ) {\n\treturn (\n\t\t( hasInt16Array && value instanceof Int16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt16Array;\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// MAIN //\n\nvar main = ( typeof Int16Array === 'function' ) ? Int16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt16Array = require( '@stdlib/assert-is-int16array' );\nvar INT16_MAX = require( '@stdlib/constants-int16-max' );\nvar INT16_MIN = require( '@stdlib/constants-int16-min' );\nvar GlobalInt16Array = require( './int16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int16Array` support\n*\n* @example\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\nfunction hasInt16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt16Array( [ 1, 3.14, -3.14, INT16_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT16_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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* Minimum signed 16-bit integer.\n*\n* @module @stdlib/constants-int16-min\n* @type {integer32}\n*\n* @example\n* var INT16_MIN = require( '@stdlib/constants-int16-min' );\n* // returns -32768\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 16-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{15})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 1000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -32768\n*/\nvar INT16_MIN = -32768|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT16_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int16\n*\n* @example\n* var ctor = require( '@stdlib/array-int16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\nvar builtin = require( './int16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int16Array === 'function' ) ? Int16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int16Array` support.\n*\n* @module @stdlib/assert-has-int16array-support\n*\n* @example\n* var hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\n*\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint16Array = ( typeof Uint16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint16Array\n*\n* @example\n* var bool = isUint16Array( new Uint16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint16Array( [] );\n* // returns false\n*/\nfunction isUint16Array( value ) {\n\treturn (\n\t\t( hasUint16Array && value instanceof Uint16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint16Array;\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// MAIN //\n\nvar main = ( typeof Uint16Array === 'function' ) ? Uint16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint16Array = require( '@stdlib/assert-is-uint16array' );\nvar UINT16_MAX = require( '@stdlib/constants-uint16-max' );\nvar GlobalUint16Array = require( './uint16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint16Array` support\n*\n* @example\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\nfunction hasUint16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT16_MAX+1, UINT16_MAX+2 ];\n\t\tarr = new GlobalUint16Array( arr );\n\t\tbool = (\n\t\t\tisUint16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT16_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 16-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint16\n*\n* @example\n* var ctor = require( '@stdlib/array-uint16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\nvar builtin = require( './uint16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint16Array === 'function' ) ? Uint16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint16Array` support.\n*\n* @module @stdlib/assert-has-uint16array-support\n*\n* @example\n* var hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\n*\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt32Array = ( typeof Int32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int32Array\n*\n* @example\n* var bool = isInt32Array( new Int32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt32Array( [] );\n* // returns false\n*/\nfunction isInt32Array( value ) {\n\treturn (\n\t\t( hasInt32Array && value instanceof Int32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt32Array;\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// MAIN //\n\nvar main = ( typeof Int32Array === 'function' ) ? Int32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt32Array = require( '@stdlib/assert-is-int32array' );\nvar INT32_MAX = require( '@stdlib/constants-int32-max' );\nvar INT32_MIN = require( '@stdlib/constants-int32-min' );\nvar GlobalInt32Array = require( './int32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int32Array` support\n*\n* @example\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\nfunction hasInt32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt32Array( [ 1, 3.14, -3.14, INT32_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT32_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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* Minimum signed 32-bit integer.\n*\n* @module @stdlib/constants-int32-min\n* @type {integer32}\n*\n* @example\n* var INT32_MIN = require( '@stdlib/constants-int32-min' );\n* // returns -2147483648\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 32-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{31})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -2147483648\n*/\nvar INT32_MIN = -2147483648|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT32_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int32\n*\n* @example\n* var ctor = require( '@stdlib/array-int32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\nvar builtin = require( './int32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int32Array === 'function' ) ? Int32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int32Array` support.\n*\n* @module @stdlib/assert-has-int32array-support\n*\n* @example\n* var hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\n*\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint32Array = ( typeof Uint32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint32Array\n*\n* @example\n* var bool = isUint32Array( new Uint32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint32Array( [] );\n* // returns false\n*/\nfunction isUint32Array( value ) {\n\treturn (\n\t\t( hasUint32Array && value instanceof Uint32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint32Array;\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// MAIN //\n\nvar main = ( typeof Uint32Array === 'function' ) ? Uint32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint32Array = require( '@stdlib/assert-is-uint32array' );\nvar UINT32_MAX = require( '@stdlib/constants-uint32-max' );\nvar GlobalUint32Array = require( './uint32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint32Array` support\n*\n* @example\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\nfunction hasUint32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT32_MAX+1, UINT32_MAX+2 ];\n\t\tarr = new GlobalUint32Array( arr );\n\t\tbool = (\n\t\t\tisUint32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT32_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 32-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint32\n*\n* @example\n* var ctor = require( '@stdlib/array-uint32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\nvar builtin = require( './uint32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint32Array === 'function' ) ? Uint32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint32Array` support.\n*\n* @module @stdlib/assert-has-uint32array-support\n*\n* @example\n* var hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\n*\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat32Array = ( typeof Float32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float32Array\n*\n* @example\n* var bool = isFloat32Array( new Float32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat32Array( [] );\n* // returns false\n*/\nfunction isFloat32Array( value ) {\n\treturn (\n\t\t( hasFloat32Array && value instanceof Float32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat32Array;\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// MAIN //\n\nvar main = ( typeof Float32Array === 'function' ) ? Float32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat32Array = require( '@stdlib/assert-is-float32array' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar GlobalFloat32Array = require( './float32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float32Array` support\n*\n* @example\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\nfunction hasFloat32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat32Array( [ 1.0, 3.14, -3.14, 5.0e40 ] );\n\t\tbool = (\n\t\t\tisFloat32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.140000104904175 &&\n\t\t\tarr[ 2 ] === -3.140000104904175 &&\n\t\t\tarr[ 3 ] === PINF\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of single-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float32\n*\n* @example\n* var ctor = require( '@stdlib/array-float32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\nvar builtin = require( './float32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float32Array === 'function' ) ? Float32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float32Array` support.\n*\n* @module @stdlib/assert-has-float32array-support\n*\n* @example\n* var hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\n*\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat64Array = ( typeof Float64Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float64Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float64Array\n*\n* @example\n* var bool = isFloat64Array( new Float64Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat64Array( [] );\n* // returns false\n*/\nfunction isFloat64Array( value ) {\n\treturn (\n\t\t( hasFloat64Array && value instanceof Float64Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float64Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat64Array;\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// MAIN //\n\nvar main = ( typeof Float64Array === 'function' ) ? Float64Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat64Array = require( '@stdlib/assert-is-float64array' );\nvar GlobalFloat64Array = require( './float64array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float64Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float64Array` support\n*\n* @example\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\nfunction hasFloat64ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat64Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat64Array( [ 1.0, 3.14, -3.14, NaN ] );\n\t\tbool = (\n\t\t\tisFloat64Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.14 &&\n\t\t\tarr[ 2 ] === -3.14 &&\n\t\t\tarr[ 3 ] !== arr[ 3 ]\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of double-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float64\n*\n* @example\n* var ctor = require( '@stdlib/array-float64' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\nvar builtin = require( './float64array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat64ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float64Array === 'function' ) ? Float64Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float64Array` support.\n*\n* @module @stdlib/assert-has-float64array-support\n*\n* @example\n* var hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\n*\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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\nvar Int8Array = require( '@stdlib/array-int8' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar Uint8ClampedArray = require( '@stdlib/array-uint8c' );\nvar Int16Array = require( '@stdlib/array-int16' );\nvar Uint16Array = require( '@stdlib/array-uint16' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar Uint32Array = require( '@stdlib/array-uint32' );\nvar Float32Array = require( '@stdlib/array-float32' );\nvar Float64Array = require( '@stdlib/array-float64' );\n\n\n// VARIABLES //\n\nvar hash;\n\n\n// FUNCTIONS //\n\n/**\n* Copies an `Int8Array`.\n*\n* @private\n* @param {Int8Array} arr - array to copy\n* @returns {Int8Array} new array\n*/\nfunction int8array( arr ) {\n\treturn new Int8Array( arr );\n}\n\n/**\n* Copies a `Uint8Array`.\n*\n* @private\n* @param {Uint8Array} arr - array to copy\n* @returns {Uint8Array} new array\n*/\nfunction uint8array( arr ) {\n\treturn new Uint8Array( arr );\n}\n\n/**\n* Copies a `Uint8ClampedArray`.\n*\n* @private\n* @param {Uint8ClampedArray} arr - array to copy\n* @returns {Uint8ClampedArray} new array\n*/\nfunction uint8clampedarray( arr ) {\n\treturn new Uint8ClampedArray( arr );\n}\n\n/**\n* Copies an `Int16Array`.\n*\n* @private\n* @param {Int16Array} arr - array to copy\n* @returns {Int16Array} new array\n*/\nfunction int16array( arr ) {\n\treturn new Int16Array( arr );\n}\n\n/**\n* Copies a `Uint16Array`.\n*\n* @private\n* @param {Uint16Array} arr - array to copy\n* @returns {Uint16Array} new array\n*/\nfunction uint16array( arr ) {\n\treturn new Uint16Array( arr );\n}\n\n/**\n* Copies an `Int32Array`.\n*\n* @private\n* @param {Int32Array} arr - array to copy\n* @returns {Int32Array} new array\n*/\nfunction int32array( arr ) {\n\treturn new Int32Array( arr );\n}\n\n/**\n* Copies a `Uint32Array`.\n*\n* @private\n* @param {Uint32Array} arr - array to copy\n* @returns {Uint32Array} new array\n*/\nfunction uint32array( arr ) {\n\treturn new Uint32Array( arr );\n}\n\n/**\n* Copies a `Float32Array`.\n*\n* @private\n* @param {Float32Array} arr - array to copy\n* @returns {Float32Array} new array\n*/\nfunction float32array( arr ) {\n\treturn new Float32Array( arr );\n}\n\n/**\n* Copies a `Float64Array`.\n*\n* @private\n* @param {Float64Array} arr - array to copy\n* @returns {Float64Array} new array\n*/\nfunction float64array( arr ) {\n\treturn new Float64Array( arr );\n}\n\n/**\n* Returns a hash of functions for copying typed arrays.\n*\n* @private\n* @returns {Object} function hash\n*/\nfunction typedarrays() {\n\tvar out = {\n\t\t'int8array': int8array,\n\t\t'uint8array': uint8array,\n\t\t'uint8clampedarray': uint8clampedarray,\n\t\t'int16array': int16array,\n\t\t'uint16array': uint16array,\n\t\t'int32array': int32array,\n\t\t'uint32array': uint32array,\n\t\t'float32array': float32array,\n\t\t'float64array': float64array\n\t};\n\treturn out;\n}\n\n\n// MAIN //\n\nhash = typedarrays();\n\n\n// EXPORTS //\n\nmodule.exports = hash;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar regexp = require( '@stdlib/utils-regexp-from-string' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar propertyNames = require( '@stdlib/utils-property-names' );\nvar propertyDescriptor = require( '@stdlib/utils-property-descriptor' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar defineProperty = require( '@stdlib/utils-define-property' );\nvar copyBuffer = require( '@stdlib/buffer-from-buffer' );\nvar typedArrays = require( './typed_arrays.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Clones a class instance.\n*\n* ## Notes\n*\n* - This should **only** be used for simple cases. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This approach should be considered **fragile**.\n* - The function is greedy, disregarding the notion of a `level`. Instead, the function deep copies all properties, as we assume the concept of `level` applies only to the class instance reference but not to its internal state. This prevents, in theory, two instances from sharing state.\n*\n*\n* @private\n* @param {Object} val - class instance\n* @returns {Object} new instance\n*/\nfunction cloneInstance( val ) {\n\tvar cache;\n\tvar names;\n\tvar name;\n\tvar refs;\n\tvar desc;\n\tvar tmp;\n\tvar ref;\n\tvar i;\n\n\tcache = [];\n\trefs = [];\n\n\tref = Object.create( getPrototypeOf( val ) );\n\tcache.push( val );\n\trefs.push( ref );\n\n\tnames = propertyNames( val );\n\tfor ( i = 0; i < names.length; i++ ) {\n\t\tname = names[ i ];\n\t\tdesc = propertyDescriptor( val, name );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( val[name] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( val[name], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( ref, name, desc );\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( ref );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( ref );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( ref );\n\t}\n\treturn ref;\n}\n\n/**\n* Copies an error object.\n*\n* @private\n* @param {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error - error to copy\n* @returns {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error copy\n*\n* @example\n* var err1 = new TypeError( 'beep' );\n*\n* var err2 = copyError( err1 );\n* // returns \n*/\nfunction copyError( error ) {\n\tvar cache = [];\n\tvar refs = [];\n\tvar keys;\n\tvar desc;\n\tvar tmp;\n\tvar key;\n\tvar err;\n\tvar i;\n\n\t// Create a new error...\n\terr = new error.constructor( error.message );\n\n\tcache.push( error );\n\trefs.push( err );\n\n\t// If a `stack` property is present, copy it over...\n\tif ( error.stack ) {\n\t\terr.stack = error.stack;\n\t}\n\t// Node.js specific (system errors)...\n\tif ( error.code ) {\n\t\terr.code = error.code;\n\t}\n\tif ( error.errno ) {\n\t\terr.errno = error.errno;\n\t}\n\tif ( error.syscall ) {\n\t\terr.syscall = error.syscall;\n\t}\n\t// Any enumerable properties...\n\tkeys = objectKeys( error );\n\tfor ( i = 0; i < keys.length; i++ ) {\n\t\tkey = keys[ i ];\n\t\tdesc = propertyDescriptor( error, key );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( error[ key ] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( error[ key ], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( err, key, desc );\n\t}\n\treturn err;\n}\n\n\n// MAIN //\n\n/**\n* Recursively performs a deep copy of an input object.\n*\n* @private\n* @param {*} val - value to copy\n* @param {(Array|Object)} copy - copy\n* @param {Array} cache - an array of visited objects\n* @param {Array} refs - an array of object references\n* @param {NonNegativeInteger} level - copy depth\n* @returns {*} deep copy\n*/\nfunction deepCopy( val, copy, cache, refs, level ) {\n\tvar parent;\n\tvar keys;\n\tvar name;\n\tvar desc;\n\tvar ctor;\n\tvar key;\n\tvar ref;\n\tvar x;\n\tvar i;\n\tvar j;\n\n\tlevel -= 1;\n\n\t// Primitives and functions...\n\tif (\n\t\ttypeof val !== 'object' ||\n\t\tval === null\n\t) {\n\t\treturn val;\n\t}\n\tif ( isBuffer( val ) ) {\n\t\treturn copyBuffer( val );\n\t}\n\tif ( isError( val ) ) {\n\t\treturn copyError( val );\n\t}\n\t// Objects...\n\tname = typeOf( val );\n\n\tif ( name === 'date' ) {\n\t\treturn new Date( +val );\n\t}\n\tif ( name === 'regexp' ) {\n\t\treturn regexp( val.toString() );\n\t}\n\tif ( name === 'set' ) {\n\t\treturn new Set( val );\n\t}\n\tif ( name === 'map' ) {\n\t\treturn new Map( val );\n\t}\n\tif (\n\t\tname === 'string' ||\n\t\tname === 'boolean' ||\n\t\tname === 'number'\n\t) {\n\t\t// If provided an `Object`, return an equivalent primitive!\n\t\treturn val.valueOf();\n\t}\n\tctor = typedArrays[ name ];\n\tif ( ctor ) {\n\t\treturn ctor( val );\n\t}\n\t// Class instances...\n\tif (\n\t\tname !== 'array' &&\n\t\tname !== 'object'\n\t) {\n\t\t// Cloning requires ES5 or higher...\n\t\tif ( typeof Object.freeze === 'function' ) {\n\t\t\treturn cloneInstance( val );\n\t\t}\n\t\treturn {};\n\t}\n\t// Arrays and plain objects...\n\tkeys = objectKeys( val );\n\tif ( level > 0 ) {\n\t\tparent = name;\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tx = val[ key ];\n\n\t\t\t// Primitive, Buffer, special class instance...\n\t\t\tname = typeOf( x );\n\t\t\tif (\n\t\t\t\ttypeof x !== 'object' ||\n\t\t\t\tx === null ||\n\t\t\t\t(\n\t\t\t\t\tname !== 'array' &&\n\t\t\t\t\tname !== 'object'\n\t\t\t\t) ||\n\t\t\t\tisBuffer( x )\n\t\t\t) {\n\t\t\t\tif ( parent === 'object' ) {\n\t\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\t\tdesc.value = deepCopy( x );\n\t\t\t\t\t}\n\t\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t\t} else {\n\t\t\t\t\tcopy[ key ] = deepCopy( x );\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Circular reference...\n\t\t\ti = indexOf( cache, x );\n\t\t\tif ( i !== -1 ) {\n\t\t\t\tcopy[ key ] = refs[ i ];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Plain array or object...\n\t\t\tref = ( isArray( x ) ) ? new Array( x.length ) : {};\n\t\t\tcache.push( x );\n\t\t\trefs.push( ref );\n\t\t\tif ( parent === 'array' ) {\n\t\t\t\tcopy[ key ] = deepCopy( x, ref, cache, refs, level );\n\t\t\t} else {\n\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\tdesc.value = deepCopy( x, ref, cache, refs, level );\n\t\t\t\t}\n\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t}\n\t\t}\n\t} else if ( name === 'array' ) {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tcopy[ key ] = val[ key ];\n\t\t}\n\t} else {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\tdefineProperty( copy, key, desc );\n\t\t}\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( copy );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( copy );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( copy );\n\t}\n\treturn copy;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepCopy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar deepCopy = require( './deep_copy.js' );\n\n\n// MAIN //\n\n/**\n* Copies or deep clones a value to an arbitrary depth.\n*\n* @param {*} value - value to copy\n* @param {NonNegativeInteger} [level=+infinity] - copy depth\n* @throws {TypeError} `level` must be a nonnegative integer\n* @returns {*} value copy\n*\n* @example\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\nfunction copy( value, level ) {\n\tvar out;\n\tif ( arguments.length > 1 ) {\n\t\tif ( !isNonNegativeInteger( level ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `level` must be a nonnegative integer. Value: `' + level + '`.' );\n\t\t}\n\t\tif ( level === 0 ) {\n\t\t\treturn value;\n\t\t}\n\t} else {\n\t\tlevel = PINF;\n\t}\n\tout = ( isArray( value ) ) ? new Array( value.length ) : {};\n\treturn deepCopy( value, out, [value], [out], level );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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* Copy or deep clone a value to an arbitrary depth.\n*\n* @module @stdlib/utils-copy\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ {'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\n\n// MODULES //\n\nvar copy = require( './copy.js' );\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an object; e.g., `{}`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an object\n*\n* @example\n* var bool = isObject( {} );\n* // returns true\n*\n* @example\n* var bool = isObject( null );\n* // returns false\n*/\nfunction isObject( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t!isArray( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObject;\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\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar objectPrototype = Object.prototype;\n\n\n// FUNCTIONS //\n\n/**\n* Tests that an object only has own properties.\n*\n* @private\n* @param {Object} obj - value to test\n* @returns {boolean} boolean indicating if an object only has own properties\n*/\nfunction ownProps( obj ) {\n\tvar key;\n\n\t// NOTE: possibility of perf boost if key enumeration order is known (see http://stackoverflow.com/questions/18531624/isplainobject-thing).\n\tfor ( key in obj ) {\n\t\tif ( !hasOwnProp( obj, key ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n\n// MAIN //\n\n/**\n* Tests if a value is a plain object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a plain object\n*\n* @example\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* @example\n* var bool = isPlainObject( null );\n* // returns false\n*/\nfunction isPlainObject( value ) {\n\tvar proto;\n\n\t// Screen for obvious non-objects...\n\tif ( !isObject( value ) ) {\n\t\treturn false;\n\t}\n\t// Objects with no prototype (e.g., `Object.create( null )`) are plain...\n\tproto = getPrototypeOf( value );\n\tif ( !proto ) {\n\t\treturn true;\n\t}\n\t// Objects having a prototype are plain if and only if they are constructed with a global `Object` function and the prototype points to the prototype of a plain object...\n\treturn (\n\t\t// Cannot have own `constructor` property:\n\t\t!hasOwnProp( value, 'constructor' ) &&\n\n\t\t// Prototype `constructor` property must be a function (see also https://bugs.jquery.com/ticket/9897 and http://stackoverflow.com/questions/18531624/isplainobject-thing):\n\t\thasOwnProp( proto, 'constructor' ) &&\n\t\tisFunction( proto.constructor ) &&\n\t\tnativeClass( proto.constructor ) === '[object Function]' &&\n\n\t\t// Test for object-specific method:\n\t\thasOwnProp( proto, 'isPrototypeOf' ) &&\n\t\tisFunction( proto.isPrototypeOf ) &&\n\n\t\t(\n\t\t\t// Test if the prototype matches the global `Object` prototype (same realm):\n\t\t\tproto === objectPrototype ||\n\n\t\t\t// Test that all properties are own properties (cross-realm; *most* likely a plain object):\n\t\t\townProps( value )\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - options to validate\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {(Error|null)} error object or null\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );\n\t}\n\tif ( hasOwnProp( options, 'url' ) ) {\n\t\topts.url = options.url;\n\t\tif ( !isString( opts.url ) ) {\n\t\t\treturn new TypeError( 'invalid option. `url` option must be a string primitive. Option: `' + opts.url + '`.' );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'message' ) ) {\n\t\topts.message = options.message;\n\t\tif ( !isString( opts.message ) ) {\n\t\t\treturn new TypeError( 'invalid option. `message` option must be a string primitive. Option: `' + opts.message + '`.' );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\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* Test if a value is a plain object.\n*\n* @module @stdlib/assert-is-plain-object\n*\n* @example\n* var isPlainObject = require( '@stdlib/assert-is-plain-object' );\n*\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* bool = isPlainObject( null );\n* // returns false\n*/\n\n// MODULES //\n\nvar isPlainObject = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar replace = require( '@stdlib/string-replace' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Returns a function which formats an error message for production.\n*\n* @param {Options} options - function options\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {Function} error formatting function\n*\n* @example\n* var opts = {\n* 'url': 'https://stdlib.io/error-decoder.html'\n* };\n*\n* var fcn = factory( opts );\n* // returns \n*/\nfunction factory( options ) {\n\tvar opts;\n\tvar err;\n\topts = copy( defaults );\n\terr = validate( opts, options );\n\tif ( err ) {\n\t\tthrow err;\n\t}\n\treturn formatProdErrorMessage;\n\n\t/**\n\t* Formats an error message for production.\n\t*\n\t* @private\n\t* @param {string} code - error code\n\t* @param {*} ...args - error message arguments\n\t* @returns {string} formatted error message\n\t*/\n\tfunction formatProdErrorMessage() {\n\t\tvar code = arguments[ 0 ];\n\t\tvar url = opts.url + '?code='+code;\n\t\tvar msg;\n\t\tvar i;\n\t\tfor ( i = 1; i < arguments.length; i++ ) {\n\t\t\turl += '&arg[]=' + encodeURIComponent( arguments[ i ] );\n\t\t}\n\t\tmsg = replace( opts.message, '{{url}}', url );\n\t\tmsg = replace( msg, '{{code}}', code );\n\t\treturn msg;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Format an error message for production.\n*\n* @module @stdlib/error-tools-fmtprodmsg\n*\n* @example\n* var formatProdErrorMessage = require( '@stdlib/error-tools-fmtprodmsg' );\n*\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar formatProdErrorMessage = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( formatProdErrorMessage, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @name formatProdErrorMessage\n* @type {Function}\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\nvar formatProdErrorMessage = factory( defaults );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["defineProperty","Object","has_define_property_support","err","builtin","objectProtoype","prototype","toStr","toString","defineGetter","__defineGetter__","defineSetter","__defineSetter__","lookupGetter","__lookupGetter__","lookupSetter","__lookupSetter__","polyfill","obj","prop","descriptor","hasValue","hasGet","hasSet","call","TypeError","__proto__","value","Error","get","set","require$$1","require$$2","lib","require$$0","main","configurable","enumerable","writable","primitive","FLG","Symbol","hasSymbols","toStringTag","tostring","native_class","v","has","hasOwnProperty","property","toStrTag","hasOwnProp","isOwn","tag","out","valueOf","String","nativeClass","test","object","isPrimitive","isObject","setReadOnly","isString","require$$3","RE_CHARS","str","s","i","length","replace","substring","re","Boolean","isBoolean","codegen","Function","self_1","self","window_1","window","global","module","exports","getThis","Self","Win","Global","arguments","root","nodeList","document","childNodes","typedarray","Int8Array","RE","check_1","reFunctionName","Array","isArray","isObjectLike","predicate","len","arrayfun","_isBuffer","constructor","isBuffer","REGEXP","match","name","ctor","slice","exec","ctorName","typeOf","type","toLowerCase","RegExp","rescape","isFunction","isRegExp","search","newval","Number","isNumber","POSITIVE_INFINITY","NEGATIVE_INFINITY","floor","Math","x","PINF","NINF","isInt","integer","isInteger","isNonNegativeInteger","getProto","getPrototypeOf","proto","reRegExp","isNan","isnan","isCollection","index_of","arr","searchElement","fromIndex","keys","has_arguments_bug","has_builtin","bool","isArguments","bool$8","detect","detect_1","native","propertyIsEnumerable","bool$7","isEnum","hasStringEnumBug","isEnumerableProperty","require$$4","builtin_wrapper","has_enumerable_prototype_bug","has_non_enumerable_properties_bug","is_constructor_prototype","w","indexOf","isConstructorPrototype","EXCLUDED_KEYS","win","bool$4","k","check","hasAutomationEqualityBug","HAS_WINDOW","HAS_ENUM_PROTO_BUG","HAS_NON_ENUM_PROPS_BUG","error","NON_ENUMERABLE","wrapper","skipConstructor","skipPrototype","isFcn","p","push","getOwnPropertyNames","propertyNames","getOwnPropertyDescriptor","propertyDescriptor","desc","Buffer","from","buffer","hasInt8Array","isInt8Array","GlobalInt8Array","INT8_MAX","hasUint8Array","Uint8Array","isUint8Array","GlobalUint8Array","UINT8_MAX","hasUint8ClampedArray","Uint8ClampedArray","isUint8ClampedArray","GlobalUint8ClampedArray","hasInt16Array","Int16Array","isInt16Array","GlobalInt16Array","INT16_MAX","hasUint16Array","Uint16Array","isUint16Array","GlobalUint16Array","UINT16_MAX","hasInt32Array","Int32Array","isInt32Array","GlobalInt32Array","INT32_MAX","hasUint32Array","Uint32Array","isUint32Array","GlobalUint32Array","UINT32_MAX","hasFloat32Array","Float32Array","isFloat32Array","GlobalFloat32Array","hasFloat64Array","Float64Array","isFloat64Array","GlobalFloat64Array","NaN","require$$5","require$$6","require$$7","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","isError","regexp","objectKeys","require$$8","require$$9","require$$10","require$$11","copyBuffer","require$$12","typedArrays","deepCopy","val","copy","cache","refs","level","parent","key","ref","j","tmp","message","stack","code","errno","syscall","copyError","Date","Set","Map","freeze","names","create","isExtensible","preventExtensions","isSealed","seal","isFrozen","cloneInstance","copy_1","objectPrototype","isPrototypeOf","ownProps","validate","opts","options","url","defaults","factory_1","msg","encodeURIComponent","formatProdErrorMessage","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","RangeError","format"],"mappings":";6kBAsBA,ICAIA,EDA0C,mBAA1BC,OAAOD,eAAkCC,OAAOD,eAAiB,KC4BrF,IAAAE,EAbA,WAEC,IAEC,OADAF,EAAgB,GAAI,IAAK,KAClB,EACN,MAAQG,GACT,OAAO,ICiBTC,EALqBH,OAAOD,eC/BxBK,EAAiBJ,OAAOK,UACxBC,EAAQF,EAAeG,SACvBC,EAAeJ,EAAeK,iBAC9BC,EAAeN,EAAeO,iBAC9BC,EAAeR,EAAeS,iBAC9BC,EAAeV,EAAeW,iBAuFlC,IAAAC,EAnDA,SAAyBC,EAAKC,EAAMC,GACnC,IAAId,EACAe,EACAC,EACAC,EAEJ,GAAoB,iBAARL,GAA4B,OAARA,GAAsC,mBAAtBX,EAAMiB,KAAMN,GAC3D,MAAM,IAAIO,UAAW,+DAAiEP,EAAM,MAE7F,GAA2B,iBAAfE,GAA0C,OAAfA,GAAoD,mBAA7Bb,EAAMiB,KAAMJ,GACzE,MAAM,IAAIK,UAAW,oEAAsEL,EAAa,MAyBzG,IAvBAC,EAAa,UAAWD,KAGtBP,EAAaW,KAAMN,EAAKC,IACxBJ,EAAaS,KAAMN,EAAKC,IAGxBb,EAAYY,EAAIQ,UAChBR,EAAIQ,UAAYrB,SAGTa,EAAKC,GACZD,EAAKC,GAASC,EAAWO,MAGzBT,EAAIQ,UAAYpB,GAEhBY,EAAKC,GAASC,EAAWO,OAG3BL,EAAW,QAASF,EACpBG,EAAW,QAASH,EAEfC,IAAcC,GAAUC,GAC5B,MAAM,IAAIK,MAAO,wHASlB,OANKN,GAAUb,GACdA,EAAae,KAAMN,EAAKC,EAAMC,EAAWS,KAErCN,GAAUZ,GACdA,EAAaa,KAAMN,EAAKC,EAAMC,EAAWU,KAEnCZ,GCrEJd,EAAU2B,EACVd,EAAWe,EAefC,EAjB+BC,IASb9B,EAEAa,EC7BdjB,EAAiBkC,EAmCrB,IAAAC,EAZA,SAAmCjB,EAAKC,EAAMQ,GAC7C3B,EAAgBkB,EAAKC,EAAM,CAC1BiB,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,KCJXM,EAL+BC,ECA/B,IAAAK,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCMjB,ICdIa,EDIJ,WACC,MACmB,mBAAXC,QACoB,iBAApBA,OAAQ,OCPPC,GAqBV,ICTAT,EDEA,WACC,OAASO,GAAqC,iBAAvBC,OAAOE,aEf/BC,EALY3C,OAAOK,UAAUE,SCAzBD,EAAQ2B,EAiCZ,IAAAW,EAPA,SAAsBC,GACrB,OAAOvC,EAAMiB,KAAMsB,IC3BhBC,EAAM9C,OAAOK,UAAU0C,eAyC3B,ICjBAf,EDIA,SAAqBN,EAAOsB,GAC3B,OACCtB,SAKMoB,EAAIvB,KAAMG,EAAOsB,IEnCrBC,EAA+B,mBAAXT,OAA0BA,OAAOE,YAAc,GCAnEQ,EAAajB,EACbS,EDIaO,ECHb3C,EAAQyB,EAwDZ,ICpCI5B,EAAU2B,EACVd,EDKJ,SAAsB6B,GACrB,IAAIM,EACAC,EACAC,EAEJ,GAAKR,QACJ,OAAOvC,EAAMiB,KAAMsB,GAEpBO,EAAMP,EAAGH,GACTS,EAAQD,EAAYL,EAAGH,GAGvB,IACCG,EAAGH,QAAgB,EAClB,MAAQxC,GACT,OAAOI,EAAMiB,KAAMsB,GASpB,OAPAQ,EAAM/C,EAAMiB,KAAMsB,GAEbM,EACJN,EAAGH,GAAgBU,SAEZP,EAAGH,GAEJW,GCdRrB,EAjBqBC,IASNjB,EAEAb,EChCXmD,ECDUC,OAAOlD,UAAUiD,QDyB/B,IEvBIE,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADA4B,EAAQ/B,KAAMG,IACP,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB6B,SAGjBhB,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,EAAW9B,EA0Bf,ICSI+B,EAAc5B,EACd6B,EDjBJ,SAAmBpC,GAClB,OAASiC,EAAajC,IAAWkC,EAAUlC,ICkBxCkC,EAAWG,EAKfF,EAAaC,EAAU,cANL/B,GAOlB8B,EAAaC,EAAU,WAAYF,GAKnC,IAAA5B,EAAiB8B,EClDbA,EAAW7B,EAAsC0B,YAKjDK,EAAW,yBAqDf,ICzCAhC,EDIA,SAAkBiC,GACjB,IACIC,EACAC,EAEJ,IAAML,EAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAGrG,GAAkB,MAAbA,EAAK,GAGT,IAAME,EADAF,EAAIG,OACI,EAAGD,GAAK,GACH,MAAbF,EAAKE,GADcA,KAO1B,YAAW,IAANA,GAAgBA,GAAK,EAClBF,EAAII,QAASL,EAAU,SAM/BE,GAHAA,EAAID,EAAIK,UAAW,EAAGH,IAGhBE,QAASL,EAAU,QAGzBC,EAAMA,EAAK,GAAMC,EAAID,EAAIK,UAAWH,KE/CrCI,EALS,ICyBT,IAAAjC,EAPA,SAAoBZ,GACnB,MAA0B,kBAAVA,GCjBbnB,ECDWiE,QAAQnE,UAAUE,SDyBjC,IEvBIiD,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADAnB,EAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAoBhC,GACnB,MAAsB,iBAAVA,IACNA,aAAiB8C,UAGjBjC,EACGkB,EAAM/B,GAEoB,qBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,GAAW9B,EAkCf,ICAI+B,GAAc5B,EACdwC,GDRJ,SAAoB/C,GACnB,OAASiC,EAAajC,IAAWkC,GAAUlC,ICSxCkC,GAAWG,EAKfF,GAAaY,GAAW,cANN1C,GAOlB8B,GAAaY,GAAW,WAAYb,IAKpC,IAAA5B,GAAiByC,GCpCjB,IAAAC,GAPA,WACC,OAAO,IAAIC,SAAU,eAAd,ICFRC,GAL4B,iBAATC,KAAsBA,KAAO,KCKhDC,GAL8B,iBAAXC,OAAwBA,OAAS,6GCAhD9D,GAA0B,iBAAX+D,GAAwBA,GAAS,KAKpDC,OAAOC,QAAUjE,OCLbwD,GAAYxC,GAAuC0B,YACnDwB,GAAUrD,GACVsD,GAAOrD,GACPsD,GAAMtB,GACNuB,sCAkDJ,IAAApD,GA7BA,SAAoBwC,GACnB,GAAKa,UAAUnB,OAAS,CACvB,IAAMK,GAAWC,GAChB,MAAM,IAAIlD,UAAW,+DAA+DkD,EAAQ,MAE7F,GAAKA,EACJ,OAAOS,KAKT,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,MAAM,IAAI3D,MAAO,uDC3Cd6D,GCOYvD,KDNZwD,GAAWD,GAAKE,UAAYF,GAAKE,SAASC,WER1CC,GAAaC,UCEbC,GAAK7D,EACLwD,GHUaA,GGTbG,GDCaA,GC6BjB,IAAAG,GAnBA,WACC,MAEe,mBAAPD,IAGe,iBAAfF,IAGa,mBAAbH,ICST,IAAAvD,GAPA,WACC,MAAO,2BCEJ8D,GAAiBlE,GADHG,EAOL+D,GAAgB,SCjCR/D,MDsCrB,IAAAD,GAAiBgE,GEtCbxC,GAAcvB,EAwClB,ICpBAD,GDWKiE,MAAMC,QACND,MAAMC,QARX,SAAkBxE,GACjB,MAAkC,mBAAzB8B,GAAa9B,IEzBnBwE,GAAUjE,GC0Bd,ICGIkE,GDbJ,SAAuBzE,GACtB,OACW,OAAVA,GACiB,iBAAVA,GCQSO,EAOLkE,GAAc,oBFR3B,SAAmBC,GAClB,GAA0B,mBAAdA,EACX,MAAM,IAAI5E,UAAW,sDAAwD4E,EAAY,MAE1F,OASA,SAAgB1E,GACf,IAAI2E,EACAlC,EACJ,IAAM+B,GAASxE,GACd,OAAO,EAGR,GAAa,KADb2E,EAAM3E,EAAM0C,QAEX,OAAO,EAER,IAAMD,EAAI,EAAGA,EAAIkC,EAAKlC,IACrB,IAAiC,IAA5BiC,EAAW1E,EAAOyC,IACtB,OAAO,EAGT,OAAO,GEpBuCmC,CAAUH,KAK1D,IAAAnE,GAAiBmE,GCvCbA,GAAelE,GA+CnB,IC3BAD,GDOA,SAAmBN,GAClB,OACCyE,GAAczE,KAGbA,EAAM6E,WAEL7E,EAAM8E,aAGgC,mBAA/B9E,EAAM8E,YAAYC,UACzB/E,EAAM8E,YAAYC,SAAU/E,KEtC5B8B,GAAcvB,EACd6D,GAAKhE,GAA0C4E,OAC/CD,GAAW1E,GAuDf,IAAAG,GAxBA,SAA0BW,GACzB,IAAI8D,EACAC,EACAC,EAEJ,IAAe,YADfD,EAAOpD,GAAaX,GAAIiE,MAAO,GAAI,KACC,UAATF,IAAqB/D,EAAE2D,YAAc,CAE/D,GAA0B,iBAD1BK,EAAOhE,EAAE2D,aACQI,KAChB,OAAOC,EAAKD,KAGb,GADAD,EAAQb,GAAGiB,KAAMF,EAAKtG,YAErB,OAAOoG,EAAO,GAGhB,OAAKF,GAAU5D,GACP,SAED+D,GCnDJI,GCkBkB/E,GDmCtB,IErDI+E,GDkBkB/E,GCAtB,ICFIgF,GHkBJ,SAAiBpE,GAChB,IAAIqE,EAGJ,OAAW,OAANrE,EACG,OAKM,YAHdqE,SAAcrE,GAINmE,GAAUnE,GAAIsE,cAEfD,GG9BJlG,GDNJ,SAAiB6B,GAChB,OAAOmE,GAAUnE,GAAIsE,eCetBnF,GAZkBC,KAOajB,GAAWiG,GCtBtCA,GAAShF,GA2Bb,ICNAD,GDFA,SAAqBN,GAEpB,MAA6B,aAApBuF,GAAQvF,IErBdqF,GCFOK,OAAO/G,UAAU0G,KD0B5B,IEvBIvD,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADAqF,GAAKxF,KAAMG,IACJ,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBN,IA0CrB,IC1CIoF,GAAUpF,EACVqF,GAAaxF,GACbgC,GAAW/B,EAAsC4B,YACjD4D,GDuBJ,SAAmB7F,GAClB,MAAsB,iBAAVA,IACNA,aAAiB0F,SAGjB7E,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MC2BxB,ICvCAM,GDmBA,SAAkBiC,EAAKuD,EAAQC,GAC9B,IAAM3D,GAAUG,GACf,MAAM,IAAIzC,UAAW,wEAA0EyC,EAAM,MAEtG,GAAKH,GAAU0D,GACdA,EAASH,GAASG,GAClBA,EAAS,IAAIJ,OAAQI,EAAQ,UAEzB,IAAMD,GAAUC,GACpB,MAAM,IAAIhG,UAAW,+FAAiGgG,EAAS,MAEhI,IAAM1D,GAAU2D,KAAaH,GAAYG,GACxC,MAAM,IAAIjG,UAAW,gGAAkGiG,EAAS,MAEjI,OAAOxD,EAAII,QAASmD,EAAQC,IEhC7B,IAAAnF,GAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCAjBM,GCjBiB0F,OCAbnH,GCAS0B,GAMS5B,UAAUE,SDkBhC,IEvBIiD,GAAc1B,EACd4F,GAAS3F,GACT0B,GFSJ,SAAe/B,GACd,IAEC,OADAnB,GAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IETLqC,GARiBN,IA2CrB,IAAAyB,GAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiBgG,KAGjBnF,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MCnCpBiC,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd0F,GDfJ,SAAmBjG,GAClB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa8D,GAAU,cANL5F,IAOlB8B,GAAa8D,GAAU,WAAY/D,IAKnC,IAAA5B,GAAiB2F,GCvBjB3F,GALmB0F,OAAOE,kBCS1B5F,GA1BaC,GAqBa4F,kBChCtBC,GCsBQC,KAAKD,MDIjB,IENA9F,GFDA,SAAoBgG,GACnB,OAAQF,GAAME,KAAOA,GGpBlBC,GAAOhG,GACPiG,GAAOpG,GACPqG,GAAQpG,GAuBZ,IAAAqG,GAXA,SAAoB1G,GACnB,OACCA,EAAQuG,IACRvG,EAAQwG,IACRC,GAAOzG,IClBLiG,GAAW1F,GAAsC0B,YACjDwE,GAAQrG,GA6BZ,IAAAQ,GAVA,SAAoBZ,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,ICvBLiG,GAAW1F,GAAsC2B,SACjDuE,GAAQrG,GA6BZ,IAAA4B,GAVA,SAAoBhC,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICMI+B,GAAc5B,EACdoG,GDdJ,SAAoB3G,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICexCkC,GAAWG,GAKfF,GAAawE,GAAW,cANNtG,IAOlB8B,GAAawE,GAAW,WAAYzE,IAKpC,IAAA5B,GAAiBqG,GCvDbA,GAAYpG,GAAuC0B,YA6BvD,IAAArB,GAVA,SAA+BZ,GAC9B,OACC2G,GAAW3G,IACXA,GAAS,GCtBP2G,GAAYpG,GAAuC2B,SA6BvD,IAAAF,GAVA,SAA+BhC,GAC9B,OACC2G,GAAW3G,IACXA,EAAM4B,WAAa,GCtBjBK,GAAc1B,GACd2B,GAAW9B,GAsCf,ICGI+B,GAAc5B,EACdqG,GDXJ,SAA+B5G,GAC9B,OAASiC,GAAajC,IAAWkC,GAAUlC,ICYxCkC,GAAWG,GAKfF,GAAayE,GAAsB,cANjBvG,IAOlB8B,GAAayE,GAAsB,WAAY1E,IAK/C,IAAA5B,GAAiBsG,GCxDbC,GAAWvI,OAAOwI,eCatB,IAAAC,GARA,SAAmBxH,GAElB,OAAOA,EAAIQ,WCPR+B,GAAcvB,EACdsG,GAAWzG,GA+Bf,IAAAd,GAnBA,SAAyBC,GACxB,IAAIwH,EAAQF,GAAUtH,GACtB,OAAKwH,GAAmB,OAAVA,EACNA,EAEgC,sBAAnCjF,GAAavC,EAAIuF,aAEdvF,EAAIuF,YAAYnG,UAEnBY,aAAejB,OACZA,OAAOK,UAGR,MCzBJF,GHIaoI,GGHbvH,GAAWe,GCFXwG,GDAatG,GAQAjC,OAAOwI,gBACZrI,GAEAa,GCoBZ,ICdAgB,GDFA,SAAyBN,GACxB,OACCA,QAGO,MAGRA,EAAQ1B,OAAQ0B,GAET6G,GAAU7G,KEzBd8G,GAAiBvG,GACjBuB,GAAc1B,EAwClB,ICrBAE,GDAA,SAAkBN,GACjB,GAAsB,iBAAVA,GAAgC,OAAVA,EACjC,OAAO,EAGR,GAAKA,aAAiBC,MACrB,OAAO,EAGR,KAAQD,GAAQ,CACf,GAA8B,mBAAzB8B,GAAa9B,GACjB,OAAO,EAERA,EAAQ8G,GAAgB9G,GAEzB,OAAO,GEdR,IAAAQ,GAPA,WACC,MAAO,oCCWJwG,GAAW5G,GADGG,EAOLyG,GAAU,SChCRzG,UCAX6B,GAAW7B,EAAsC0B,YACjD+E,GFyCaA,GEXjB,ICdA1G,GDAA,SAAuBiC,GACtB,IAAMH,GAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAMrG,OAHAA,EAAMyE,KAAW3B,KAAM9C,IAGN,IAAImD,OAAQnD,EAAI,GAAIA,EAAI,IAAO,MEJjD,IAAA/B,GAPA,SAAgB8F,GACf,OAASA,GAAMA,GCfZL,GAAW1F,GAAsC0B,YACjDgF,GCcQ1G,GDmBZ,IAAAK,GAVA,SAAgBZ,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,IE3BLiG,GAAW1F,GAAsC2B,SACjD+E,GDcQ1G,GCeZ,IAAAyB,GAVA,SAAgBhC,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd2G,GDfJ,SAAgBlH,GACf,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa+E,GAAO,cANF7G,IAOlB8B,GAAa+E,GAAO,WAAYhF,IAKhC,IAAA5B,GAAiB4G,GCxDbP,GAAYpG,GAkChB,IClCI2G,GAAQ3G,GACR4G,GDmBJ,SAAuBnH,GACtB,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QENqB,kBDnBzBN,GAAW/B,EAAsC4B,YACjD0E,GAAYtE,GAAuCJ,YA0GvD,IAAAmF,GAhDA,SAAkBC,EAAKC,EAAeC,GACrC,IAAI5C,EACAlC,EACJ,IAAM0E,GAAcE,KAAUjF,GAAUiF,GACvC,MAAM,IAAIvH,UAAW,0EAA4EuH,EAAM,MAGxG,GAAa,KADb1C,EAAM0C,EAAI3E,QAET,OAAQ,EAET,GAA0B,IAArBmB,UAAUnB,OAAe,CAC7B,IAAMiE,GAAWY,GAChB,MAAM,IAAIzH,UAAW,6DAA+DyH,EAAY,MAEjG,GAAKA,GAAa,EAAI,CACrB,GAAKA,GAAa5C,EACjB,OAAQ,EAETlC,EAAI8E,OAEJ9E,EAAIkC,EAAM4C,GACD,IACR9E,EAAI,QAINA,EAAI,EAGL,GAAKyE,GAAOI,IACX,KAAQ7E,EAAIkC,EAAKlC,IAChB,GAAKyE,GAAOG,EAAI5E,IACf,OAAOA,OAIT,KAAQA,EAAIkC,EAAKlC,IAChB,GAAK4E,EAAK5E,KAAQ6E,EACjB,OAAO7E,EAIV,OAAQ,GErDTnC,GALcC,GClBd,IAAA9B,GAPA,SAAeuB,GACd,OAAO1B,OAAOkJ,KAAMlJ,OAAQ0B,KCrBzBwH,GAAOjH,GAmCX,IAAAkH,GAPA,WACC,OAlBD,WACC,OAA8C,KAArCD,GAAM3D,YAAe,IAAKnB,OAiB5BX,CAAM,EAAG,ICxBjB2F,QALoC,IAAhBpJ,OAAOkJ,KCAvB1F,GAAcvB,EA+BlB,IC1BIoH,GD0BJnH,GAPA,SAAsBR,GACrB,MAAkC,uBAAzB8B,GAAa9B,ICzBnB4H,GAAcrH,GA2BdsH,GAPJ,WACC,OAAOD,GAAa/D,WAMdiE,GAKP,IC3BIH,GD2BJI,GAAiBJ,GEDjBK,GAL2B1J,OAAOK,UAAUsJ,qBDHxCC,IAvBS3H,GAiBGV,KAAM,OAAQ,KAW9B,IE5BIuC,GAAW7B,EACX2G,GAAQ9G,GAAmC6B,YAC3C0E,GAAYtG,GAAuC4B,YACnDkG,GAAS9F,GACT+F,GFwBaT,GE6BjB,IAAAnH,GAzBA,SAA+BR,EAAOsB,GACrC,IAAIqG,EACJ,OACC3H,YAKD2H,EAAOQ,GAAOtI,KAAMG,EAAOsB,KACb8G,IAAoBhG,GAAUpC,IAIzCkH,GAFF5F,GAAYA,IAGXqF,GAAWrF,IACXA,GAAY,GACZA,EAAWtB,EAAM0C,OAGZiF,IC3BRrH,GAL2BC,GCnBvBiB,GAAajB,EACb8H,GAAuBjI,GACvBoE,GAAUnE,GACVsG,GAAYtE,GCiChB,IAAA/B,GAjBwBC,GACbH,GDQX,SAAsBJ,GACrB,OACW,OAAVA,GACiB,iBAAVA,IACNwE,GAASxE,IACc,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QAhCS4F,YAiCf9G,GAAYxB,EAAO,YAClBqI,GAAsBrI,EAAO,WEtC5B4H,GAAcrH,GACd9B,GAAU2B,GAKVgF,GAAQb,MAAM5F,UAAUyG,MA+B5B,IAAAmD,GAVA,SAAevI,GACd,OAAK4H,GAAa5H,GACVvB,GAAS2G,GAAMvF,KAAMG,IAEtBvB,GAASuB,ICnBjB,ICAAwI,GAZ2BjI,IDK3B,cCEuC,aCWvCkI,IAlB2BlI,GAKjB,CACT1B,SAAY,MAO0B,YCCvC,ICJI8I,GDIJe,GAPA,SAAiC1I,GAChC,OAASA,EAAM8E,aAAe9E,EAAM8E,YAAYnG,YAAcqB,GER3D2I,GAAwB,oBAAXtF,YAA2B,EAASA,ODAjD7B,GAAajB,EACbqI,GAAUxI,GACVmF,GAASlF,GACTwI,GAAyBxG,GACzByG,wPACAC,GCAaJ,GD2CbK,GAzBJ,WACC,IAAIC,EACJ,GAAuB,cAAlB1D,GAAQwD,IACZ,OAAO,EAER,IAAME,KAAKF,GACV,KAEmC,IAAjCH,GAASE,GAAeG,IACxBzH,GAAYuH,GAAKE,IACJ,OAAbF,GAAKE,IACkB,WAAvB1D,GAAQwD,GAAKE,KAEbJ,GAAwBE,GAAKE,IAE7B,MAAQzK,GACT,OAAO,EAGT,OAAO,EAMD0K,GAKP,IErDIvB,GAA2B,oBAAXtE,OCAhB8F,GHqDaxB,GGpDbkB,GAAyBzI,GACzBgJ,GDGazB,GCuBjB,IC5BIlD,GAAelE,GACfiB,GAAapB,EACbwH,GAAcvH,GACdgJ,GAAqBhH,GACrBiH,GAAyBhB,GACzBO,GDSJ,SAAkB7I,GACjB,IAAoB,IAAfoJ,KAAyBD,GAC7B,OAAON,GAAwB7I,GAEhC,IACC,OAAO6I,GAAwB7I,GAC9B,MAAQuJ,GACT,OAAO,ICfLC,iHAyEJ,IC7EI/K,GAAU4B,GACVoJ,GAAUpH,GACV/C,GDuBJ,SAAeU,GACd,IAAI0J,EACAC,EACAC,EACAjI,EACAsH,EACAY,EACApH,EAGJ,GADAd,EAAM,GACDiG,GAAa5H,GAAU,CAE3B,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,YAGb,OAAO8C,EAER,GAAsB,iBAAV3B,GAEX,GAAKA,EAAM0C,OAAS,IAAMlB,GAAYxB,EAAO,KAC5C,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,gBAGR,CAEN,IAAe,KADf+K,EAA2B,mBAAV5J,KACQyE,GAAczE,GACtC,OAAO2B,EAERgI,EAAkBN,IAAsBO,EAEzC,IAAMX,KAAKjJ,EACF2J,GAAuB,cAANV,IAAuBzH,GAAYxB,EAAOiJ,IAClEtH,EAAImI,KAAMjI,OAAQoH,IAGpB,GAAKK,GAEJ,IADAI,EAAkBb,GAAwB7I,GACpCyC,EAAI,EAAGA,EAAI+G,GAAe9G,OAAQD,IACvCoH,EAAIL,GAAgB/G,GACZiH,GAAyB,gBAANG,IAAyBrI,GAAYxB,EAAO6J,IACtElI,EAAImI,KAAMjI,OAAQgI,IAIrB,OAAOlI,GEnDRrB,GDrBkBF,GADIG,KA6BbkJ,GAEAhL,GAGDa,GE7BRoI,QALmD,IAA/BpJ,OAAOyL,oBCAvBC,GAAgB1L,OAAOyL,oBAgC3B,IChCIvC,GAAOjH,GCgCX,IAAAD,GAjBkBC,GFUlB,SAA8BP,GAC7B,OAAOgK,GAAe1L,OAAQ0B,KCA/B,SAA8BA,GAC7B,OAAOwH,GAAMlJ,OAAQ0B,KEtBtB0H,QALwD,IAApCpJ,OAAO2L,yBCAvBC,GAAqB5L,OAAO2L,yBAuChC,ICvCIzI,GAAajB,ECkCjB,IAAAD,GAjBkBC,GFUlB,SAAmCP,EAAOsB,GACzC,IAAI6I,EACJ,OAAKnK,cAIa,KADlBmK,EAAOD,GAAoBlK,EAAOsB,IAF1B,KAG4B6I,GCLrC,SAAmCnK,EAAOsB,GACzC,OAAKE,GAAYxB,EAAOsB,GAChB,CACNb,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,EAAOsB,IAGX,iyqBEvBR,ICDId,uJCb2B4J,ODc3B9K,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GAjB2BC,KASnBC,GAEAlB,GEjBJqI,GANapH,GACJH,GAKiBiK,MCN1BtF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAI,GAVA,SAAqB8J,GACpB,IAAMvF,GAAUuF,GACf,MAAM,IAAIxK,UAAW,oDAAsDwK,EAAS,KAErF,OAAOF,GAAOC,KAAMC,IC1BjBvF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAd,GAVA,SAAqBgL,GACpB,IAAMvF,GAAUuF,GACf,MAAM,IAAIxK,UAAW,oDAAsDwK,EAAS,KAErF,OAAO,IAAIF,GAAQE,ICOpBhK,GHtBiBqH,GGMNvH,GACIC,GClBXyB,GAAcvB,EAKdgK,GAAsC,mBAAdpG,UA6B5B,IClCI3D,GAA8B,mBAAd2D,UAA6BA,UAAY,KCAzDqG,GFwBJ,SAAsBxK,GACrB,OACGuK,IAAgBvK,aAAiBmE,WACV,uBAAzBrC,GAAa9B,IExBXyK,GDEajK,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAgC,mBAApBoD,GACX,OAAO,EAGR,IACCpD,EAAM,IAAIoD,GAAiB,CAAE,EAAG,MAAO,KAAMC,MAC7C/C,EACC6C,GAAanD,IACA,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEO,MDDZA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb8B,mBAAd0F,UAA6BA,eAAY,EDczD7E,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB0BC,KFSlB9B,GAEAa,GGvBJwC,GAAcvB,EAKdoK,GAAwC,mBAAfC,WA6B7B,IClCIpK,GAA+B,mBAAfoK,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuB7K,GACtB,OACG2K,IAAiB3K,aAAiB4K,YACX,wBAAzB9I,GAAa9B,IEzBX8K,GDGatK,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArByD,GACX,OAAO,EAGR,IAECzD,EAAM,IAAIyD,GADVzD,EAAM,CAAE,EAAG,MAAO,KAAM0D,IAAaA,MAErCpD,EACCkD,GAAcxD,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ0D,MAAb1D,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCb+B,mBAAfmM,WAA8BA,gBAAa,EDc3DtL,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdyK,GAAsD,mBAAtBC,kBA6BpC,IClCIzK,GAAsC,mBAAtByK,kBAAqCA,kBAAoB,KCAzEC,GFwBJ,SAA8BlL,GAC7B,OACGgL,IAAwBhL,aAAiBiL,mBAClB,+BAAzBnJ,GAAa9B,IE1BXmL,GDIa3K,GCuCjB,IAAAA,GA7BA,WACC,IAAImH,EACAN,EAEJ,GAAwC,mBAA5B8D,GACX,OAAO,EAGR,IACC9D,EAAM,IAAI8D,GAAyB,EAAG,EAAG,EAAG,EAAG,KAAM,KAAM,IAAK,MAChExD,EACCuD,GAAqB7D,IACR,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,MAAbA,EAAK,IACQ,MAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbsC,mBAAtBwM,kBAAqCA,uBAAoB,EDczE3L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjBkCC,KFS1B9B,GAEAa,GGvBJwC,GAAcvB,EAKd6K,GAAwC,mBAAfC,WA6B7B,IClCI7K,GAA+B,mBAAf6K,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBtL,GACtB,OACGoL,IAAiBpL,aAAiBqL,YACX,wBAAzBvJ,GAAa9B,IExBXuL,GDEa/K,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArBkE,GACX,OAAO,EAGR,IACClE,EAAM,IAAIkE,GAAkB,CAAE,EAAG,MAAO,KAAMC,QAC9C7D,EACC2D,GAAcjE,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,QDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAf4M,WAA8BA,gBAAa,EDc3D/L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdkL,GAA0C,mBAAhBC,YA6B9B,IClCIlL,GAAgC,mBAAhBkL,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwB3L,GACvB,OACGyL,IAAkBzL,aAAiB0L,aACZ,yBAAzB5J,GAAa9B,IEzBX4L,GDGapL,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBuE,GACX,OAAO,EAGR,IAECvE,EAAM,IAAIuE,GADVvE,EAAM,CAAE,EAAG,MAAO,KAAMwE,MAAcA,QAEtClE,EACCgE,GAAetE,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQwE,QAAbxE,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhBiN,YAA+BA,iBAAc,EDc7DpM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKduL,GAAwC,mBAAfC,WA6B7B,IClCIvL,GAA+B,mBAAfuL,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBhM,GACtB,OACG8L,IAAiB9L,aAAiB+L,YACX,wBAAzBjK,GAAa9B,IExBXiM,GDEazL,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB4E,GACX,OAAO,EAGR,IACC5E,EAAM,IAAI4E,GAAkB,CAAE,EAAG,MAAO,KAAMC,aAC9CvE,EACCqE,GAAc3E,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,aDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAfsN,WAA8BA,gBAAa,EDc3DzM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd4L,GAA0C,mBAAhBC,YA6B9B,IClCI5L,GAAgC,mBAAhB4L,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwBrM,GACvB,OACGmM,IAAkBnM,aAAiBoM,aACZ,yBAAzBtK,GAAa9B,IEzBXsM,GDGa9L,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBiF,GACX,OAAO,EAGR,IAECjF,EAAM,IAAIiF,GADVjF,EAAM,CAAE,EAAG,MAAO,KAAMkF,WAAcA,aAEtC5E,EACC0E,GAAehF,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQkF,aAAblF,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhB2N,YAA+BA,iBAAc,EDc7D9M,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdiM,GAA4C,mBAAjBC,aA6B/B,IClCIjM,GAAiC,mBAAjBiM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB1M,GACxB,OACGwM,IAAmBxM,aAAiByM,cACb,0BAAzB3K,GAAa9B,IE1BXuG,GAAOnG,GACPuM,GDGanM,GCqCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvBsF,GACX,OAAO,EAGR,IACCtF,EAAM,IAAIsF,GAAoB,CAAE,EAAK,MAAO,KAAM,OAClDhF,EACC+E,GAAgBrF,IACH,IAAbA,EAAK,IACQ,oBAAbA,EAAK,KACS,oBAAdA,EAAK,IACLA,EAAK,KAAQd,GAEb,MAAQ/H,GACTmJ,GAAO,EAER,OAAOA,GCtBR,ICDIlJ,GCbiC,mBAAjBgO,aAAgCA,kBAAe,EDc/DnN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB6BC,KFSrB9B,GAEAa,GGvBJwC,GAAcvB,EAKdqM,GAA4C,mBAAjBC,aA6B/B,IClCIrM,GAAiC,mBAAjBqM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB9M,GACxB,OACG4M,IAAmB5M,aAAiB6M,cACb,0BAAzB/K,GAAa9B,IE1BX+M,GDIavM,GCoCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvB0F,GACX,OAAO,EAGR,IACC1F,EAAM,IAAI0F,GAAoB,CAAE,EAAK,MAAO,KAAMC,MAClDrF,EACCmF,GAAgBzF,IACH,IAAbA,EAAK,IACQ,OAAbA,EAAK,KACS,OAAdA,EAAK,IACLA,EAAK,IAAQA,EAAK,GAElB,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCrBR,ICKIxC,GANA1G,GCbiC,mBAAjBoO,aAAgCA,kBAAe,EDc/DvN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCajBkF,GET4B5E,KFSrB9B,GAEAa,GAMR,IG7BI6E,GAAY5D,GACZqK,GAAaxK,GACb6K,GAAoB5K,GACpBgL,GAAahJ,GACbqJ,GAAcpD,GACdyD,GAAakB,GACbb,GAAcc,GACdT,GAAeU,GACfN,GHqBa1H,GGJjB,SAASiI,GAAW/F,GACnB,OAAO,IAAIlD,GAAWkD,GAUvB,SAASgG,GAAYhG,GACpB,OAAO,IAAIuD,GAAYvD,GAUxB,SAASiG,GAAmBjG,GAC3B,OAAO,IAAI4D,GAAmB5D,GAU/B,SAASkG,GAAYlG,GACpB,OAAO,IAAIgE,GAAYhE,GAUxB,SAASmG,GAAanG,GACrB,OAAO,IAAIqE,GAAarE,GAUzB,SAASoG,GAAYpG,GACpB,OAAO,IAAI0E,GAAY1E,GAUxB,SAASqG,GAAarG,GACrB,OAAO,IAAI+E,GAAa/E,GAUzB,SAASsG,GAActG,GACtB,OAAO,IAAIoF,GAAcpF,GAU1B,SAASuG,GAAcvG,GACtB,OAAO,IAAIwF,GAAcxF,GAgC1B,IClJI7F,GAAajB,EACbiE,GAAUpE,GACV2E,GAAW1E,GACXwN,GAAUxL,GACVkD,GAAS+C,GACTwF,GAASb,GACTrE,GAAUsE,GACVa,GAAaZ,GACbnD,GAAgBgE,GAChB9D,GAAqB+D,GACrBnH,GAAiBoH,GACjB7P,GAAiB8P,EACjBC,GAAaC,GACbC,GD+GO,CACTlB,UAAaA,GACbC,WAAcA,GACdC,kBAAqBA,GACrBC,WAAcA,GACdC,YAAeA,GACfC,WAAcA,GACdC,YAAeA,GACfC,aAAgBA,GAChBC,aAAgBA,ICQlB,SAASW,GAAUC,EAAKC,EAAMC,EAAOC,EAAMC,GAC1C,IAAIC,EACArH,EACAtC,EACAiF,EACAhF,EACA2J,EACAC,EACAzI,EACA7D,EACAuM,EAKJ,GAHAJ,GAAS,EAIO,iBAARJ,GACC,OAARA,EAEA,OAAOA,EAER,GAAKzJ,GAAUyJ,GACd,OAAOJ,GAAYI,GAEpB,GAAKX,GAASW,GACb,OAnFF,SAAoBjF,GACnB,IAEI/B,EACA2C,EACA8E,EACAH,EACAtQ,EACAiE,EAPAiM,EAAQ,GACRC,EAAO,GA8BX,IArBAnQ,EAAM,IAAI+K,EAAMzE,YAAayE,EAAM2F,SAEnCR,EAAM5E,KAAMP,GACZoF,EAAK7E,KAAMtL,GAGN+K,EAAM4F,QACV3Q,EAAI2Q,MAAQ5F,EAAM4F,OAGd5F,EAAM6F,OACV5Q,EAAI4Q,KAAO7F,EAAM6F,MAEb7F,EAAM8F,QACV7Q,EAAI6Q,MAAQ9F,EAAM8F,OAEd9F,EAAM+F,UACV9Q,EAAI8Q,QAAU/F,EAAM+F,SAGrB9H,EAAOuG,GAAYxE,GACb9G,EAAI,EAAGA,EAAI+E,EAAK9E,OAAQD,IAC7BqM,EAAMtH,EAAM/E,GACZ0H,EAAOD,GAAoBX,EAAOuF,GAC7BtN,GAAY2I,EAAM,WACtB8E,EAAQzK,GAAS+E,EAAOuF,IAAY,GAAK,GACzC3E,EAAKnK,MAAQuO,GAAUhF,EAAOuF,GAAOG,EAAKP,EAAOC,GAAO,IAEzDtQ,GAAgBG,EAAKsQ,EAAK3E,GAE3B,OAAO3L,EA0CC+Q,CAAWf,GAKnB,GAAc,UAFdtJ,EAAOK,GAAQiJ,IAGd,OAAO,IAAIgB,MAAOhB,GAEnB,GAAc,WAATtJ,EACJ,OAAO4I,GAAQU,EAAI3P,YAEpB,GAAc,QAATqG,EACJ,OAAO,IAAIuK,IAAKjB,GAEjB,GAAc,QAATtJ,EACJ,OAAO,IAAIwK,IAAKlB,GAEjB,GACU,WAATtJ,GACS,YAATA,GACS,WAATA,EAGA,OAAOsJ,EAAI5M,UAGZ,GADAuD,EAAOmJ,GAAapJ,GAEnB,OAAOC,EAAMqJ,GAGd,GACU,UAATtJ,GACS,WAATA,EAGA,MAA8B,mBAAlB5G,OAAOqR,OA1KrB,SAAwBnB,GACvB,IAAIE,EACAkB,EACA1K,EACAyJ,EACAxE,EACA8E,EACAF,EACAtM,EAUJ,IARAiM,EAAQ,GACRC,EAAO,GAEPI,EAAMzQ,OAAOuR,OAAQ/I,GAAgB0H,IACrCE,EAAM5E,KAAM0E,GACZG,EAAK7E,KAAMiF,GAEXa,EAAQ5F,GAAewE,GACjB/L,EAAI,EAAGA,EAAImN,EAAMlN,OAAQD,IAC9ByC,EAAO0K,EAAOnN,GACd0H,EAAOD,GAAoBsE,EAAKtJ,GAC3B1D,GAAY2I,EAAM,WACtB8E,EAAQzK,GAASgK,EAAItJ,IAAY,GAAK,GACtCiF,EAAKnK,MAAQuO,GAAUC,EAAItJ,GAAO+J,EAAKP,EAAOC,GAAO,IAEtDtQ,GAAgB0Q,EAAK7J,EAAMiF,GAW5B,OATM7L,OAAOwR,aAActB,IAC1BlQ,OAAOyR,kBAAmBhB,GAEtBzQ,OAAO0R,SAAUxB,IACrBlQ,OAAO2R,KAAMlB,GAETzQ,OAAO4R,SAAU1B,IACrBlQ,OAAOqR,OAAQZ,GAETA,EAuIEoB,CAAe3B,GAEhB,GAIR,GADAhH,EAAOuG,GAAYS,GACdI,EAAQ,EAEZ,IADAC,EAAS3J,EACH8J,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAE7B1I,EAAIkI,EADJM,EAAMtH,EAAMwH,IAIZ9J,EAAOK,GAAQe,GAED,iBAANA,GACD,OAANA,GAEU,UAATpB,GACS,WAATA,GAEDH,GAAUuB,GAEM,WAAXuI,GACJ1E,EAAOD,GAAoBsE,EAAKM,GAC3BtN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQuO,GAAUjI,IAExBjI,GAAgBoQ,EAAMK,EAAK3E,IAE3BsE,EAAMK,GAAQP,GAAUjI,IAMd,KADZ7D,EAAImG,GAAS8F,EAAOpI,KAMpByI,EAAQvK,GAAS8B,GAAQ,IAAI/B,MAAO+B,EAAE5D,QAAW,GACjDgM,EAAM5E,KAAMxD,GACZqI,EAAK7E,KAAMiF,GACK,UAAXF,EACJJ,EAAMK,GAAQP,GAAUjI,EAAGyI,EAAKL,EAAOC,EAAMC,IAE7CzE,EAAOD,GAAoBsE,EAAKM,GAC3BtN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQuO,GAAUjI,EAAGyI,EAAKL,EAAOC,EAAMC,IAE7CvQ,GAAgBoQ,EAAMK,EAAK3E,KAd3BsE,EAAMK,GAAQH,EAAMlM,QAiBhB,GAAc,UAATyC,EACX,IAAM8J,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAE7BP,EADAK,EAAMtH,EAAMwH,IACER,EAAKM,QAGpB,IAAME,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAC7BF,EAAMtH,EAAMwH,GACZ7E,EAAOD,GAAoBsE,EAAKM,GAChCzQ,GAAgBoQ,EAAMK,EAAK3E,GAY7B,OATM7L,OAAOwR,aAActB,IAC1BlQ,OAAOyR,kBAAmBtB,GAEtBnQ,OAAO0R,SAAUxB,IACrBlQ,OAAO2R,KAAMxB,GAETnQ,OAAO4R,SAAU1B,IACrBlQ,OAAOqR,OAAQlB,GAETA,EAMR,IC3RIjK,GAAUjE,GACVqG,GAAuBxG,GAAmD6B,YAC1EsE,GAAOlG,GACPkO,GDwRaA,GCtOjB,IAAA6B,GAnBA,SAAepQ,EAAO4O,GACrB,IAAIjN,EACJ,GAAKkC,UAAUnB,OAAS,EAAI,CAC3B,IAAMkE,GAAsBgI,GAC3B,MAAM,IAAI9O,UAAW,oEAAsE8O,EAAQ,MAEpG,GAAe,IAAVA,EACJ,OAAO5O,OAGR4O,EAAQrI,GAGT,OADA5E,EAAQ6C,GAASxE,GAAY,IAAIuE,MAAOvE,EAAM0C,QAAW,GAClD6L,GAAUvO,EAAO2B,EAAK,CAAC3B,GAAQ,CAAC2B,GAAMiN,ICd9CtO,GALWC,GC5BPiE,GAAUjE,GA8Bd,IC9BI2B,GDmBJ,SAAmBlC,GAClB,MACkB,iBAAVA,GACG,OAAVA,IACCwE,GAASxE,ICtBR4F,GAAaxF,GACb0G,GAAiBzG,GACjBmB,GAAaa,EACbP,GAAcwG,EAKd+H,GAAkB/R,OAAOK,UAgF7B,IAAA6B,GAvCA,SAAwBR,GACvB,IAAI+G,EAGJ,QAAM7E,GAAUlC,OAIhB+G,EAAQD,GAAgB9G,MAOtBwB,GAAYxB,EAAO,gBAGpBwB,GAAYuF,EAAO,gBACnBnB,GAAYmB,EAAMjC,cACmB,sBAArChD,GAAaiF,EAAMjC,cAGnBtD,GAAYuF,EAAO,kBACnBnB,GAAYmB,EAAMuJ,iBAIjBvJ,IAAUsJ,IAzDb,SAAmB9Q,GAClB,IAAIuP,EAGJ,IAAMA,KAAOvP,EACZ,IAAMiC,GAAYjC,EAAKuP,GACtB,OAAO,EAGT,OAAO,EAmDLyB,CAAUvQ,MCjFTkC,GCegB3B,GDdhBiB,GAAapB,EACbgC,GAAW/B,EAAsC4B,YAqCrD,wJEvCIU,GAAUpC,GACVkO,GAAOrO,GACPoQ,GFeJ,SAAmBC,EAAMC,GACxB,OAAMxO,GAAUwO,GAGXlP,GAAYkP,EAAS,SACzBD,EAAKE,IAAMD,EAAQC,KACbvO,GAAUqO,EAAKE,MACb,IAAI7Q,UAAW,qEAAuE2Q,EAAKE,IAAM,MAGrGnP,GAAYkP,EAAS,aACzBD,EAAKvB,QAAUwB,EAAQxB,SACjB9M,GAAUqO,EAAKvB,UACb,IAAIpP,UAAW,yEAA2E2Q,EAAKvB,QAAU,MAG3G,KAdC,IAAIpP,UAAW,iEAAmE4Q,EAAU,OEhBjGE,GAAWvO,GAwDf,IAAAwO,GAnCA,SAAkBH,GACjB,IAAID,EACAjS,EAGJ,GAFAiS,EAAOhC,GAAMmC,IACbpS,EAAMgS,GAAUC,EAAMC,GAErB,MAAMlS,EAEP,OAUA,WACC,IAEIsS,EACArO,EAHA2M,EAAOvL,UAAW,GAClB8M,EAAMF,EAAKE,IAAM,SAASvB,EAG9B,IAAM3M,EAAI,EAAGA,EAAIoB,UAAUnB,OAAQD,IAClCkO,GAAO,UAAYI,mBAAoBlN,UAAWpB,IAInD,OAFAqO,EAAMnO,GAAS8N,EAAKvB,QAAS,UAAWyB,GACxCG,EAAMnO,GAASmO,EAAK,WAAY1B,KCtC9B4B,GCbUzQ,GACCH,IDWGG,EAOLyQ,GAAwB,UALvB3Q,IAUd,IAAAC,GAAiB0Q,UEiFjB,WACC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjP,EACAwM,EACAvM,EASJ,IANAwO,EAAUpN,UAAW,GACrBqN,EAASrN,UAAW,GAGpBsN,GADAG,EAAQzN,UAAW,GADnBwN,GAHAD,EAAQvN,UAAW,IAGLnB,UAECA,OACf8O,EAAMN,EACAzO,EAAI,EAAGA,EAAI4O,EAAO5O,IAAM,CAI7B,GAHAgP,EAAIL,EAAO3O,GACXuM,EAAInL,UAAWpB,EAAE,GAEH,WADd8O,EAAOD,EAAO7O,EAAE0O,IAEVnC,EAAI,EACRA,EAAI,EACOA,GAAKyC,IAChBzC,EAAIyC,EAAI,QAEH,GAAc,SAATF,EACNvC,EAAI,GACRA,GAAKyC,GACI,GAEG,KADXzC,GAAKyC,KAEJzC,GAAKyC,GAGIzC,GAAKyC,IAChBzC,GAAKyC,IACKA,IACTzC,GAAKyC,QAGD,GAAKzC,EAAI,GAAKA,GAAKyC,EACzB,MAAM,IAAIC,WAAYC,GAAQ,+FAAgGlP,EAAGuM,KAElIxM,EAAIyO,EAASxO,IAGJ,GAAgB,IAAXyO,EACbM,GAAOxC,EAAIxM,EAEXgP,GAAOxC,EAAIxM,EAGb,OAAOgP"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 25f81ac..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..4d9b415 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).sub2ind=r()}(this,(function(){"use strict";function t(t){var r=t.default;if("function"==typeof r){var e=function(){return r.apply(this,arguments)};e.prototype=r.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(t).forEach((function(r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})})),e}var r="function"==typeof Object.defineProperty?Object.defineProperty:null;var e=function(){try{return r({},"x",{}),!0}catch(t){return!1}},n=Object.defineProperty,o=Object.prototype,i=o.toString,u=o.__defineGetter__,a=o.__defineSetter__,f=o.__lookupGetter__,c=o.__lookupSetter__;var s=function(t,r,e){var n,s,l,h;if("object"!=typeof t||null===t||"[object Array]"===i.call(t))throw new TypeError("invalid argument. First argument must be an object. Value: `"+t+"`.");if("object"!=typeof e||null===e||"[object Array]"===i.call(e))throw new TypeError("invalid argument. Property descriptor must be an object. Value: `"+e+"`.");if((s="value"in e)&&(f.call(t,r)||c.call(t,r)?(n=t.__proto__,t.__proto__=o,delete t[r],t[r]=e.value,t.__proto__=n):t[r]=e.value),l="get"in e,h="set"in e,s&&(l||h))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return l&&u&&u.call(t,r,e.get),h&&a&&a.call(t,r,e.set),t},l=n,h=s,p=e()?l:h,y=p;var v=function(t,r,e){y(t,r,{configurable:!1,enumerable:!1,writable:!1,value:e})},g=v;var w=function(t){return"string"==typeof t};var d=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var b=function(){return d&&"symbol"==typeof Symbol.toStringTag},m=Object.prototype.toString,A=m;var E=function(t){return A.call(t)},_=Object.prototype.hasOwnProperty;var O=function(t,r){return null!=t&&_.call(t,r)},P="function"==typeof Symbol?Symbol.toStringTag:"",j=O,R=P,T=m;var U=E,S=function(t){var r,e,n;if(null==t)return T.call(t);e=t[R],r=j(t,R);try{t[R]=void 0}catch(r){return T.call(t)}return n=T.call(t),r?t[R]=e:delete t[R],n},I=b()?S:U,B=String.prototype.valueOf;var Y=I,x=function(t){try{return B.call(t),!0}catch(t){return!1}},C=b();var M=function(t){return"object"==typeof t&&(t instanceof String||(C?x(t):"[object String]"===Y(t)))},L=w,F=M;var D=g,N=function(t){return L(t)||F(t)},k=M;D(N,"isPrimitive",w),D(N,"isObject",k);var V=N,z=V.isPrimitive,G=/[-\/\\^$*+?.()|[\]{}]/g;var X=function(t){var r,e;if(!z(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");if("/"===t[0])for(e=t.length-1;e>=0&&"/"!==t[e];e--);return void 0===e||e<=0?t.replace(G,"\\$&"):(r=(r=t.substring(1,e)).replace(G,"\\$&"),t=t[0]+r+t.substring(e))},$=/./;var H=function(t){return"boolean"==typeof t},W=Boolean.prototype.toString;var q=I,J=function(t){try{return W.call(t),!0}catch(t){return!1}},Z=b();var K=function(t){return"object"==typeof t&&(t instanceof Boolean||(Z?J(t):"[object Boolean]"===q(t)))},Q=H,tt=K;var rt=g,et=function(t){return Q(t)||tt(t)},nt=K;rt(et,"isPrimitive",H),rt(et,"isObject",nt);var ot=et;var it=function(){return new Function("return this;")()},ut="object"==typeof self?self:null,at="object"==typeof window?window:null,ft="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},ct="object"==typeof ft?ft:null;module.exports=ct;var st=ot.isPrimitive,lt=it,ht=ut,pt=at,yt=t(Object.freeze({__proto__:null}));var vt=function(t){if(arguments.length){if(!st(t))throw new TypeError("invalid argument. Must provide a boolean primitive. Value: `"+t+"`.");if(t)return lt()}if(ht)return ht;if(pt)return pt;if(yt)return yt;throw new Error("unexpected error. Unable to resolve global object.")},gt=vt(),wt=gt.document&>.document.childNodes,dt=Int8Array,bt=$,mt=wt,At=dt;var Et=function(){return"function"==typeof bt||"object"==typeof At||"function"==typeof mt};var _t=function(){return/^\s*function\s*([^(]*)/i},Ot=_t;g(Ot,"REGEXP",_t());var Pt=Ot,jt=I;var Rt=Array.isArray?Array.isArray:function(t){return"[object Array]"===jt(t)},Tt=Rt;var Ut=function(t){return null!==t&&"object"==typeof t};g(Ut,"isObjectLikeArray",function(t){if("function"!=typeof t)throw new TypeError("invalid argument. Must provide a function. Value: `"+t+"`.");return function(r){var e,n;if(!Tt(r))return!1;if(0===(e=r.length))return!1;for(n=0;ndr&&br(t)},Ar=hr.isPrimitive,Er=mr;var _r=function(t){return Ar(t)&&Er(t)},Or=hr.isObject,Pr=mr;var jr=function(t){return Or(t)&&Pr(t.valueOf())},Rr=_r,Tr=jr;var Ur=g,Sr=function(t){return Rr(t)||Tr(t)},Ir=jr;Ur(Sr,"isPrimitive",_r),Ur(Sr,"isObject",Ir);var Br=Sr,Yr=Br.isPrimitive;var xr=function(t){return Yr(t)&&t>=0},Cr=Br.isObject;var Mr=function(t){return Cr(t)&&t.valueOf()>=0},Lr=xr,Fr=Mr;var Dr=g,Nr=function(t){return Lr(t)||Fr(t)},kr=Mr;Dr(Nr,"isPrimitive",xr),Dr(Nr,"isObject",kr);var Vr=Nr,zr=Object.getPrototypeOf;var Gr=function(t){return t.__proto__},Xr=I,$r=Gr;var Hr=function(t){var r=$r(t);return r||null===r?r:"[object Function]"===Xr(t.constructor)?t.constructor.prototype:t instanceof Object?Object.prototype:null},Wr=zr,qr=Hr,Jr=zt(Object.getPrototypeOf)?Wr:qr;var Zr=function(t){return null==t?null:(t=Object(t),Jr(t))},Kr=Zr,Qr=I;var te=function(t){if("object"!=typeof t||null===t)return!1;if(t instanceof Error)return!0;for(;t;){if("[object Error]"===Qr(t))return!0;t=Kr(t)}return!1};var re=function(){return/^\/((?:\\\/|[^\/])+)\/([imgy]*)$/},ee=re;g(ee,"REGEXP",re());var ne=V.isPrimitive,oe=ee;var ie=function(t){if(!ne(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");return(t=oe().exec(t))?new RegExp(t[1],t[2]):null};var ue=function(t){return t!=t},ae=hr.isPrimitive,fe=ue;var ce=function(t){return ae(t)&&fe(t)},se=hr.isObject,le=ue;var he=function(t){return se(t)&&le(t.valueOf())},pe=ce,ye=he;var ve=g,ge=function(t){return pe(t)||ye(t)},we=he;ve(ge,"isPrimitive",ce),ve(ge,"isObject",we);var de=ge,be=gr;var me=de,Ae=function(t){return"object"==typeof t&&null!==t&&"number"==typeof t.length&&be(t.length)&&t.length>=0&&t.length<=9007199254740991},Ee=V.isPrimitive,_e=Br.isPrimitive;var Oe=function(t,r,e){var n,o;if(!Ae(t)&&!Ee(t))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+t+"`.");if(0===(n=t.length))return-1;if(3===arguments.length){if(!_e(e))throw new TypeError("invalid argument. `fromIndex` must be an integer. Value: `"+e+"`.");if(e>=0){if(e>=n)return-1;o=e}else(o=n+e)<0&&(o=0)}else o=0;if(me(r)){for(;o=0&&r=0&&t.length<=4294967295&&Ge(t,"callee")&&!Xe(t,"callee")},qe=We,Je=je,Ze=Array.prototype.slice;var Ke=function(t){return qe(t)?Je(Ze.call(t)):Je(t)};var Qe=ze((function(){}),"prototype"),tn=!ze({toString:null},"toString");var rn,en=function(t){return t.constructor&&t.constructor.prototype===t},nn="undefined"==typeof window?void 0:window,on=O,un=Pe,an=kt,fn=en,cn=["console","external","frame","frameElement","frames","innerHeight","innerWidth","outerHeight","outerWidth","pageXOffset","pageYOffset","parent","scrollLeft","scrollTop","scrollX","scrollY","self","webkitIndexedDB","webkitStorageInfo","window"],sn=nn;rn=function(){var t;if("undefined"===an(sn))return!1;for(t in sn)try{-1===un(cn,t)&&on(sn,t)&&null!==sn[t]&&"object"===an(sn[t])&&fn(sn[t])}catch(t){return!0}return!1}();var ln="undefined"!=typeof window,hn=rn,pn=en,yn=ln;var vn=St,gn=O,wn=We,dn=Qe,bn=tn,mn=function(t){if(!1===yn&&!hn)return pn(t);try{return pn(t)}catch(t){return!1}},An=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"];var En=je,_n=Ke,On=function(t){var r,e,n,o,i,u,a;if(o=[],wn(t)){for(a=0;a0&&!gn(t,"0"))for(a=0;a>18&63]+xn[o>>12&63]+xn[o>>6&63]+xn[63&o]);return i.join("")}function Nn(t){var r;Ln||Fn();for(var e=t.length,n=e%3,o="",i=[],u=16383,a=0,f=e-n;af?f:a+u));return 1===n?(r=t[e-1],o+=xn[r>>2],o+=xn[r<<4&63],o+="=="):2===n&&(r=(t[e-2]<<8)+t[e-1],o+=xn[r>>10],o+=xn[r>>4&63],o+=xn[r<<2&63],o+="="),i.push(o),i.join("")}function kn(t,r,e,n,o){var i,u,a=8*o-n-1,f=(1<>1,s=-7,l=e?o-1:0,h=e?-1:1,p=t[r+l];for(l+=h,i=p&(1<<-s)-1,p>>=-s,s+=a;s>0;i=256*i+t[r+l],l+=h,s-=8);for(u=i&(1<<-s)-1,i>>=-s,s+=n;s>0;u=256*u+t[r+l],l+=h,s-=8);if(0===i)i=1-c;else{if(i===f)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),i-=c}return(p?-1:1)*u*Math.pow(2,i-n)}function Vn(t,r,e,n,o,i){var u,a,f,c=8*i-o-1,s=(1<>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,y=n?1:-1,v=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,u=s):(u=Math.floor(Math.log(r)/Math.LN2),r*(f=Math.pow(2,-u))<1&&(u--,f*=2),(r+=u+l>=1?h/f:h*Math.pow(2,1-l))*f>=2&&(u++,f/=2),u+l>=s?(a=0,u=s):u+l>=1?(a=(r*f-1)*Math.pow(2,o),u+=l):(a=r*Math.pow(2,l-1)*Math.pow(2,o),u=0));o>=8;t[e+p]=255&a,p+=y,a/=256,o-=8);for(u=u<0;t[e+p]=255&u,p+=y,u/=256,c-=8);t[e+p-y]|=128*v}var zn={}.toString,Gn=Array.isArray||function(t){return"[object Array]"==zn.call(t)};Wn.TYPED_ARRAY_SUPPORT=void 0===ft.TYPED_ARRAY_SUPPORT||ft.TYPED_ARRAY_SUPPORT;var Xn=$n();function $n(){return Wn.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Hn(t,r){if($n()=$n())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+$n().toString(16)+" bytes");return 0|t}function to(t){return!(null==t||!t._isBuffer)}function ro(t,r){if(to(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return Uo(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return So(t).length;default:if(n)return Uo(t).length;r=(""+r).toLowerCase(),n=!0}}function eo(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return wo(this,r,e);case"utf8":case"utf-8":return po(this,r,e);case"ascii":return vo(this,r,e);case"latin1":case"binary":return go(this,r,e);case"base64":return ho(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return bo(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function no(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function oo(t,r,e,n,o){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0){if(!o)return-1;e=0}if("string"==typeof r&&(r=Wn.from(r,n)),to(r))return 0===r.length?-1:io(t,r,e,n,o);if("number"==typeof r)return r&=255,Wn.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):io(t,[r],e,n,o);throw new TypeError("val must be string, number or Buffer")}function io(t,r,e,n,o){var i,u=1,a=t.length,f=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,a/=2,f/=2,e/=2}function c(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(o){var s=-1;for(i=e;ia&&(e=a-f),i=e;i>=0;i--){for(var l=!0,h=0;ho&&(n=o):n=o;var i=r.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var u=0;u>8,o=e%256,i.push(o),i.push(n);return i}(r,t.length-e),t,e,n)}function ho(t,r,e){return 0===r&&e===t.length?Nn(t):Nn(t.slice(r,e))}function po(t,r,e){e=Math.min(t.length,e);for(var n=[],o=r;o239?4:c>223?3:c>191?2:1;if(o+l<=e)switch(l){case 1:c<128&&(s=c);break;case 2:128==(192&(i=t[o+1]))&&(f=(31&c)<<6|63&i)>127&&(s=f);break;case 3:i=t[o+1],u=t[o+2],128==(192&i)&&128==(192&u)&&(f=(15&c)<<12|(63&i)<<6|63&u)>2047&&(f<55296||f>57343)&&(s=f);break;case 4:i=t[o+1],u=t[o+2],a=t[o+3],128==(192&i)&&128==(192&u)&&128==(192&a)&&(f=(15&c)<<18|(63&i)<<12|(63&u)<<6|63&a)>65535&&f<1114112&&(s=f)}null===s?(s=65533,l=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=l}return function(t){var r=t.length;if(r<=yo)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),""},Wn.prototype.compare=function(t,r,e,n,o){if(!to(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),r<0||e>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&r>=e)return 0;if(n>=o)return-1;if(r>=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),a=Math.min(i,u),f=this.slice(n,o),c=t.slice(r,e),s=0;so)&&(e=o),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return uo(this,t,r,e);case"utf8":case"utf-8":return ao(this,t,r,e);case"ascii":return fo(this,t,r,e);case"latin1":case"binary":return co(this,t,r,e);case"base64":return so(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return lo(this,t,r,e);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},Wn.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var yo=4096;function vo(t,r,e){var n="";e=Math.min(t.length,e);for(var o=r;on)&&(e=n);for(var o="",i=r;ie)throw new RangeError("Trying to access beyond buffer length")}function Ao(t,r,e,n,o,i){if(!to(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>o||rt.length)throw new RangeError("Index out of range")}function Eo(t,r,e,n){r<0&&(r=65535+r+1);for(var o=0,i=Math.min(t.length-e,2);o>>8*(n?o:1-o)}function _o(t,r,e,n){r<0&&(r=4294967295+r+1);for(var o=0,i=Math.min(t.length-e,4);o>>8*(n?o:3-o)&255}function Oo(t,r,e,n,o,i){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function Po(t,r,e,n,o){return o||Oo(t,0,e,4),Vn(t,r,e,n,23,4),e+4}function jo(t,r,e,n,o){return o||Oo(t,0,e,8),Vn(t,r,e,n,52,8),e+8}Wn.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(o*=256);)n+=this[t+--r]*o;return n},Wn.prototype.readUInt8=function(t,r){return r||mo(t,1,this.length),this[t]},Wn.prototype.readUInt16LE=function(t,r){return r||mo(t,2,this.length),this[t]|this[t+1]<<8},Wn.prototype.readUInt16BE=function(t,r){return r||mo(t,2,this.length),this[t]<<8|this[t+1]},Wn.prototype.readUInt32LE=function(t,r){return r||mo(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Wn.prototype.readUInt32BE=function(t,r){return r||mo(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Wn.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||mo(t,r,this.length);for(var n=this[t],o=1,i=0;++i=(o*=128)&&(n-=Math.pow(2,8*r)),n},Wn.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||mo(t,r,this.length);for(var n=r,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*r)),i},Wn.prototype.readInt8=function(t,r){return r||mo(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Wn.prototype.readInt16LE=function(t,r){r||mo(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},Wn.prototype.readInt16BE=function(t,r){r||mo(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},Wn.prototype.readInt32LE=function(t,r){return r||mo(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Wn.prototype.readInt32BE=function(t,r){return r||mo(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Wn.prototype.readFloatLE=function(t,r){return r||mo(t,4,this.length),kn(this,t,!0,23,4)},Wn.prototype.readFloatBE=function(t,r){return r||mo(t,4,this.length),kn(this,t,!1,23,4)},Wn.prototype.readDoubleLE=function(t,r){return r||mo(t,8,this.length),kn(this,t,!0,52,8)},Wn.prototype.readDoubleBE=function(t,r){return r||mo(t,8,this.length),kn(this,t,!1,52,8)},Wn.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||Ao(this,t,r,e,Math.pow(2,8*e)-1,0);var o=1,i=0;for(this[r]=255&t;++i=0&&(i*=256);)this[r+o]=t/i&255;return r+e},Wn.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,1,255,0),Wn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},Wn.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,65535,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):Eo(this,t,r,!0),r+2},Wn.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,65535,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):Eo(this,t,r,!1),r+2},Wn.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,4294967295,0),Wn.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):_o(this,t,r,!0),r+4},Wn.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,4294967295,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):_o(this,t,r,!1),r+4},Wn.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Ao(this,t,r,e,o-1,-o)}var i=0,u=1,a=0;for(this[r]=255&t;++i>0)-a&255;return r+e},Wn.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Ao(this,t,r,e,o-1,-o)}var i=e-1,u=1,a=0;for(this[r+i]=255&t;--i>=0&&(u*=256);)t<0&&0===a&&0!==this[r+i+1]&&(a=1),this[r+i]=(t/u>>0)-a&255;return r+e},Wn.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,1,127,-128),Wn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},Wn.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,32767,-32768),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):Eo(this,t,r,!0),r+2},Wn.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,32767,-32768),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):Eo(this,t,r,!1),r+2},Wn.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,2147483647,-2147483648),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):_o(this,t,r,!0),r+4},Wn.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):_o(this,t,r,!1),r+4},Wn.prototype.writeFloatLE=function(t,r,e){return Po(this,t,r,!0,e)},Wn.prototype.writeFloatBE=function(t,r,e){return Po(this,t,r,!1,e)},Wn.prototype.writeDoubleLE=function(t,r,e){return jo(this,t,r,!0,e)},Wn.prototype.writeDoubleBE=function(t,r,e){return jo(this,t,r,!1,e)},Wn.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--o)t[o+r]=this[o+e];else if(i<1e3||!Wn.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(i=r;i55295&&e<57344){if(!o){if(e>56319){(r-=3)>-1&&i.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&i.push(239,191,189);continue}o=e;continue}if(e<56320){(r-=3)>-1&&i.push(239,191,189),o=e;continue}e=65536+(o-55296<<10|e-56320)}else o&&(r-=3)>-1&&i.push(239,191,189);if(o=null,e<128){if((r-=1)<0)break;i.push(e)}else if(e<2048){if((r-=2)<0)break;i.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;i.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;i.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return i}function So(t){return function(t){var r,e,n,o,i,u;Ln||Fn();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[a-2]?2:"="===t[a-1]?1:0,u=new Mn(3*a/4-i),n=i>0?a-4:a;var f=0;for(r=0,e=0;r>16&255,u[f++]=o>>8&255,u[f++]=255&o;return 2===i?(o=Cn[t.charCodeAt(r)]<<2|Cn[t.charCodeAt(r+1)]>>4,u[f++]=255&o):1===i&&(o=Cn[t.charCodeAt(r)]<<10|Cn[t.charCodeAt(r+1)]<<4|Cn[t.charCodeAt(r+2)]>>2,u[f++]=o>>8&255,u[f++]=255&o),u}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Ro,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Io(t,r,e,n){for(var o=0;o=r.length||o>=t.length);++o)r[o+e]=t[o];return o}function Bo(t){return null!=t&&(!!t._isBuffer||Yo(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&Yo(t.slice(0,0))}(t))}function Yo(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var xo=Object.freeze({__proto__:null,Buffer:Wn,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),Wn.alloc(+t)},isBuffer:Bo,kMaxLength:Xn}),Co=Wn;module.exports=Co;var Mo=Bt,Lo=t(Object.freeze({__proto__:null}));var Fo=function(){var t,r;if("function"!=typeof Lo)return!1;try{r="function"==typeof Lo.from?Lo.from([1,2,3,4]):new Lo([1,2,3,4]),t=Mo(r)&&1===r[0]&&2===r[1]&&3===r[2]&&4===r[3]}catch(r){t=!1}return t},Do=Fo;var No=t(xo).Buffer,ko=function(){throw new Error("not implemented")},Vo=Do()?No:ko,zo=zt(Vo.from),Go=Bt,Xo=Vo;var $o=function(t){if(!Go(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return Xo.from(t)},Ho=Bt,Wo=Vo;var qo=function(t){if(!Ho(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return new Wo(t)},Jo=zo?$o:qo,Zo=I,Ko="function"==typeof Int8Array;var Qo="function"==typeof Int8Array?Int8Array:null,ti=function(t){return Ko&&t instanceof Int8Array||"[object Int8Array]"===Zo(t)},ri=Qo;var ei=function(){var t,r;if("function"!=typeof ri)return!1;try{r=new ri([1,3.14,-3.14,128]),t=ti(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-128===r[3]}catch(r){t=!1}return t};var ni="function"==typeof Int8Array?Int8Array:void 0,oi=function(){throw new Error("not implemented")},ii=ei()?ni:oi,ui=I,ai="function"==typeof Uint8Array;var fi="function"==typeof Uint8Array?Uint8Array:null,ci=function(t){return ai&&t instanceof Uint8Array||"[object Uint8Array]"===ui(t)},si=fi;var li=function(){var t,r;if("function"!=typeof si)return!1;try{r=new si(r=[1,3.14,-3.14,256,257]),t=ci(r)&&1===r[0]&&3===r[1]&&253===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var hi="function"==typeof Uint8Array?Uint8Array:void 0,pi=function(){throw new Error("not implemented")},yi=li()?hi:pi,vi=I,gi="function"==typeof Uint8ClampedArray;var wi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:null,di=function(t){return gi&&t instanceof Uint8ClampedArray||"[object Uint8ClampedArray]"===vi(t)},bi=wi;var mi=function(){var t,r;if("function"!=typeof bi)return!1;try{r=new bi([-1,0,1,3.14,4.99,255,256]),t=di(r)&&0===r[0]&&0===r[1]&&1===r[2]&&3===r[3]&&5===r[4]&&255===r[5]&&255===r[6]}catch(r){t=!1}return t};var Ai="function"==typeof Uint8ClampedArray?Uint8ClampedArray:void 0,Ei=function(){throw new Error("not implemented")},_i=mi()?Ai:Ei,Oi=I,Pi="function"==typeof Int16Array;var ji="function"==typeof Int16Array?Int16Array:null,Ri=function(t){return Pi&&t instanceof Int16Array||"[object Int16Array]"===Oi(t)},Ti=ji;var Ui=function(){var t,r;if("function"!=typeof Ti)return!1;try{r=new Ti([1,3.14,-3.14,32768]),t=Ri(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-32768===r[3]}catch(r){t=!1}return t};var Si="function"==typeof Int16Array?Int16Array:void 0,Ii=function(){throw new Error("not implemented")},Bi=Ui()?Si:Ii,Yi=I,xi="function"==typeof Uint16Array;var Ci="function"==typeof Uint16Array?Uint16Array:null,Mi=function(t){return xi&&t instanceof Uint16Array||"[object Uint16Array]"===Yi(t)},Li=Ci;var Fi=function(){var t,r;if("function"!=typeof Li)return!1;try{r=new Li(r=[1,3.14,-3.14,65536,65537]),t=Mi(r)&&1===r[0]&&3===r[1]&&65533===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var Di="function"==typeof Uint16Array?Uint16Array:void 0,Ni=function(){throw new Error("not implemented")},ki=Fi()?Di:Ni,Vi=I,zi="function"==typeof Int32Array;var Gi="function"==typeof Int32Array?Int32Array:null,Xi=function(t){return zi&&t instanceof Int32Array||"[object Int32Array]"===Vi(t)},$i=Gi;var Hi=function(){var t,r;if("function"!=typeof $i)return!1;try{r=new $i([1,3.14,-3.14,2147483648]),t=Xi(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-2147483648===r[3]}catch(r){t=!1}return t};var Wi="function"==typeof Int32Array?Int32Array:void 0,qi=function(){throw new Error("not implemented")},Ji=Hi()?Wi:qi,Zi=I,Ki="function"==typeof Uint32Array;var Qi="function"==typeof Uint32Array?Uint32Array:null,tu=function(t){return Ki&&t instanceof Uint32Array||"[object Uint32Array]"===Zi(t)},ru=Qi;var eu=function(){var t,r;if("function"!=typeof ru)return!1;try{r=new ru(r=[1,3.14,-3.14,4294967296,4294967297]),t=tu(r)&&1===r[0]&&3===r[1]&&4294967293===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var nu="function"==typeof Uint32Array?Uint32Array:void 0,ou=function(){throw new Error("not implemented")},iu=eu()?nu:ou,uu=I,au="function"==typeof Float32Array;var fu="function"==typeof Float32Array?Float32Array:null,cu=function(t){return au&&t instanceof Float32Array||"[object Float32Array]"===uu(t)},su=pr,lu=fu;var hu=function(){var t,r;if("function"!=typeof lu)return!1;try{r=new lu([1,3.14,-3.14,5e40]),t=cu(r)&&1===r[0]&&3.140000104904175===r[1]&&-3.140000104904175===r[2]&&r[3]===su}catch(r){t=!1}return t};var pu="function"==typeof Float32Array?Float32Array:void 0,yu=function(){throw new Error("not implemented")},vu=hu()?pu:yu,gu=I,wu="function"==typeof Float64Array;var du="function"==typeof Float64Array?Float64Array:null,bu=function(t){return wu&&t instanceof Float64Array||"[object Float64Array]"===gu(t)},mu=du;var Au=function(){var t,r;if("function"!=typeof mu)return!1;try{r=new mu([1,3.14,-3.14,NaN]),t=bu(r)&&1===r[0]&&3.14===r[1]&&-3.14===r[2]&&r[3]!=r[3]}catch(r){t=!1}return t};var Eu,_u="function"==typeof Float64Array?Float64Array:void 0,Ou=function(){throw new Error("not implemented")};Eu=Au()?_u:Ou;var Pu=ii,ju=yi,Ru=_i,Tu=Bi,Uu=ki,Su=Ji,Iu=iu,Bu=vu,Yu=Eu;function xu(t){return new Pu(t)}function Cu(t){return new ju(t)}function Mu(t){return new Ru(t)}function Lu(t){return new Tu(t)}function Fu(t){return new Uu(t)}function Du(t){return new Su(t)}function Nu(t){return new Iu(t)}function ku(t){return new Bu(t)}function Vu(t){return new Yu(t)}var zu=O,Gu=Rt,Xu=Bt,$u=te,Hu=kt,Wu=ie,qu=Pe,Ju=Pn,Zu=Un,Ku=Yn,Qu=Zr,ta=p,ra=Jo,ea={int8array:xu,uint8array:Cu,uint8clampedarray:Mu,int16array:Lu,uint16array:Fu,int32array:Du,uint32array:Nu,float32array:ku,float64array:Vu};function na(t,r,e,n,o){var i,u,a,f,c,s,l,h,p,y;if(o-=1,"object"!=typeof t||null===t)return t;if(Xu(t))return ra(t);if($u(t))return function(t){var r,e,n,o,i,u,a=[],f=[];for(i=new t.constructor(t.message),a.push(t),f.push(i),t.stack&&(i.stack=t.stack),t.code&&(i.code=t.code),t.errno&&(i.errno=t.errno),t.syscall&&(i.syscall=t.syscall),r=Ju(t),u=0;u0)for(i=a,y=0;y1){if(!ia(r))throw new TypeError("invalid argument. `level` must be a nonnegative integer. Value: `"+r+"`.");if(0===r)return t}else r=ua;return e=oa(t)?new Array(t.length):{},aa(t,e,[t],[e],r)},ca=fa,sa=Rt;var la=function(t){return"object"==typeof t&&null!==t&&!sa(t)},ha=zt,pa=Zr,ya=O,va=I,ga=Object.prototype;var wa=function(t){var r;return!!la(t)&&(!(r=pa(t))||!ya(t,"constructor")&&ya(r,"constructor")&&ha(r.constructor)&&"[object Function]"===va(r.constructor)&&ya(r,"isPrototypeOf")&&ha(r.isPrototypeOf)&&(r===ga||function(t){var r;for(r in t)if(!ya(t,r))return!1;return!0}(t)))},da=wa,ba=O,ma=V.isPrimitive;var Aa={url:"https://stdlib.io/docs/api/latest/error-decoder.html",message:"Minified stdlib error code: {{code}}. Visit {{url}} for the full message."},Ea=Kt,_a=ca,Oa=function(t,r){return da(r)?ba(r,"url")&&(t.url=r.url,!ma(t.url))?new TypeError("invalid option. `url` option must be a string primitive. Option: `"+t.url+"`."):ba(r,"message")&&(t.message=r.message,!ma(t.message))?new TypeError("invalid option. `message` option must be a string primitive. Option: `"+t.message+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.")},Pa=Aa;var ja=function(t){var r,e;if(r=_a(Pa),e=Oa(r,t))throw e;return function(){var t,e,n=arguments[0],o=r.url+"?code="+n;for(e=1;e=f&&(s=f-1);else if("wrap"===u)s<0?(s+=f)<0&&0!==(s%=f)&&(s+=f):s>=f&&(s-=f)>=f&&(s%=f);else if(s<0||s>=f)throw new RangeError(Ta("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",l,s));(c=t[l])<0&&0===r?a-=s*c:a+=s*c}return a}})); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..e1abfe1 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/utils-define-property/lib/define_property.js","../node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js","../node_modules/@stdlib/utils-define-property/lib/builtin.js","../node_modules/@stdlib/utils-define-property/lib/polyfill.js","../node_modules/@stdlib/utils-define-property/lib/index.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/primitive.js","../node_modules/@stdlib/assert-has-symbol-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostring.js","../node_modules/@stdlib/utils-native-class/lib/native_class.js","../node_modules/@stdlib/assert-has-own-property/lib/main.js","../node_modules/@stdlib/assert-has-own-property/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostringtag.js","../node_modules/@stdlib/utils-native-class/lib/polyfill.js","../node_modules/@stdlib/utils-native-class/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/try2valueof.js","../node_modules/@stdlib/assert-is-string/lib/valueof.js","../node_modules/@stdlib/assert-is-string/lib/object.js","../node_modules/@stdlib/assert-is-string/lib/main.js","../node_modules/@stdlib/assert-is-string/lib/index.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/main.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/re.js","../node_modules/@stdlib/assert-is-boolean/lib/primitive.js","../node_modules/@stdlib/assert-is-boolean/lib/try2serialize.js","../node_modules/@stdlib/assert-is-boolean/lib/tostring.js","../node_modules/@stdlib/assert-is-boolean/lib/object.js","../node_modules/@stdlib/assert-is-boolean/lib/main.js","../node_modules/@stdlib/assert-is-boolean/lib/index.js","../node_modules/@stdlib/utils-global/lib/codegen.js","../node_modules/@stdlib/utils-global/lib/self.js","../node_modules/@stdlib/utils-global/lib/window.js","../node_modules/@stdlib/utils-global/lib/global.js","../node_modules/@stdlib/utils-global/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/nodelist.js","../node_modules/@stdlib/utils-global/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/typedarray.js","../node_modules/@stdlib/utils-type-of/lib/check.js","../node_modules/@stdlib/regexp-function-name/lib/main.js","../node_modules/@stdlib/regexp-function-name/lib/index.js","../node_modules/@stdlib/regexp-function-name/lib/regexp.js","../node_modules/@stdlib/assert-is-array/lib/main.js","../node_modules/@stdlib/assert-is-array/lib/index.js","../node_modules/@stdlib/assert-tools-array-function/lib/arrayfcn.js","../node_modules/@stdlib/assert-is-object-like/lib/main.js","../node_modules/@stdlib/assert-is-object-like/lib/index.js","../node_modules/@stdlib/assert-is-buffer/lib/main.js","../node_modules/@stdlib/assert-is-buffer/lib/index.js","../node_modules/@stdlib/utils-constructor-name/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/typeof.js","../node_modules/@stdlib/utils-constructor-name/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/polyfill.js","../node_modules/@stdlib/utils-type-of/lib/index.js","../node_modules/@stdlib/assert-is-function/lib/main.js","../node_modules/@stdlib/assert-is-function/lib/index.js","../node_modules/@stdlib/assert-is-regexp/lib/try2exec.js","../node_modules/@stdlib/assert-is-regexp/lib/exec.js","../node_modules/@stdlib/assert-is-regexp/lib/main.js","../node_modules/@stdlib/string-replace/lib/replace.js","../node_modules/@stdlib/string-replace/lib/index.js","../node_modules/@stdlib/assert-is-number/lib/primitive.js","../node_modules/@stdlib/number-ctor/lib/index.js","../node_modules/@stdlib/number-ctor/lib/number.js","../node_modules/@stdlib/assert-is-number/lib/try2serialize.js","../node_modules/@stdlib/assert-is-number/lib/tostring.js","../node_modules/@stdlib/assert-is-number/lib/object.js","../node_modules/@stdlib/assert-is-number/lib/main.js","../node_modules/@stdlib/assert-is-number/lib/index.js","../node_modules/@stdlib/constants-float64-pinf/lib/index.js","../node_modules/@stdlib/constants-float64-ninf/lib/index.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/is_integer.js","../node_modules/@stdlib/math-base-special-floor/lib/main.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-integer/lib/integer.js","../node_modules/@stdlib/assert-is-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-integer/lib/object.js","../node_modules/@stdlib/assert-is-integer/lib/main.js","../node_modules/@stdlib/assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/object.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/main.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/index.js","../node_modules/@stdlib/utils-get-prototype-of/lib/native.js","../node_modules/@stdlib/utils-get-prototype-of/lib/proto.js","../node_modules/@stdlib/utils-get-prototype-of/lib/polyfill.js","../node_modules/@stdlib/utils-get-prototype-of/lib/detect.js","../node_modules/@stdlib/utils-get-prototype-of/lib/get_prototype_of.js","../node_modules/@stdlib/utils-get-prototype-of/lib/index.js","../node_modules/@stdlib/assert-is-error/lib/main.js","../node_modules/@stdlib/assert-is-error/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/main.js","../node_modules/@stdlib/regexp-regexp/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/regexp.js","../node_modules/@stdlib/utils-regexp-from-string/lib/from_string.js","../node_modules/@stdlib/utils-regexp-from-string/lib/index.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/primitive.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-nan/lib/object.js","../node_modules/@stdlib/assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-collection/lib/main.js","../node_modules/@stdlib/utils-index-of/lib/index_of.js","../node_modules/@stdlib/constants-array-max-typed-array-length/lib/index.js","../node_modules/@stdlib/utils-index-of/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin.js","../node_modules/@stdlib/utils-keys/lib/has_arguments_bug.js","../node_modules/@stdlib/utils-keys/lib/has_builtin.js","../node_modules/@stdlib/assert-is-arguments/lib/main.js","../node_modules/@stdlib/assert-is-arguments/lib/detect.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/has_string_enumerability_bug.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/native.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/main.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/index.js","../node_modules/@stdlib/assert-is-arguments/lib/polyfill.js","../node_modules/@stdlib/assert-is-arguments/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin_wrapper.js","../node_modules/@stdlib/utils-noop/lib/noop.js","../node_modules/@stdlib/utils-keys/lib/has_enumerable_prototype_bug.js","../node_modules/@stdlib/utils-keys/lib/has_non_enumerable_properties_bug.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype.js","../node_modules/@stdlib/utils-keys/lib/has_automation_equality_bug.js","../node_modules/@stdlib/utils-keys/lib/window.js","../node_modules/@stdlib/utils-keys/lib/has_window.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype_wrapper.js","../node_modules/@stdlib/utils-keys/lib/polyfill.js","../node_modules/@stdlib/utils-keys/lib/main.js","../node_modules/@stdlib/utils-keys/lib/index.js","../node_modules/@stdlib/utils-property-names/lib/has_builtin.js","../node_modules/@stdlib/utils-property-names/lib/builtin.js","../node_modules/@stdlib/utils-property-names/lib/polyfill.js","../node_modules/@stdlib/utils-property-names/lib/index.js","../node_modules/@stdlib/utils-property-descriptor/lib/has_builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/polyfill.js","../node_modules/@stdlib/utils-property-descriptor/lib/index.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/buffer.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/main.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/polyfill.js","../node_modules/@stdlib/buffer-ctor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/buffer.js","../node_modules/@stdlib/buffer-from-buffer/lib/has_from.js","../node_modules/@stdlib/buffer-from-buffer/lib/main.js","../node_modules/@stdlib/buffer-from-buffer/lib/polyfill.js","../node_modules/@stdlib/buffer-from-buffer/lib/index.js","../node_modules/@stdlib/assert-is-int8array/lib/main.js","../node_modules/@stdlib/assert-has-int8array-support/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/main.js","../node_modules/@stdlib/constants-int8-min/lib/index.js","../node_modules/@stdlib/array-int8/lib/polyfill.js","../node_modules/@stdlib/array-int8/lib/index.js","../node_modules/@stdlib/array-int8/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8array/lib/main.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/main.js","../node_modules/@stdlib/array-uint8/lib/polyfill.js","../node_modules/@stdlib/array-uint8/lib/index.js","../node_modules/@stdlib/array-uint8/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8clampedarray/lib/main.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/main.js","../node_modules/@stdlib/array-uint8c/lib/polyfill.js","../node_modules/@stdlib/array-uint8c/lib/index.js","../node_modules/@stdlib/array-uint8c/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/index.js","../node_modules/@stdlib/assert-is-int16array/lib/main.js","../node_modules/@stdlib/assert-has-int16array-support/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/main.js","../node_modules/@stdlib/constants-int16-min/lib/index.js","../node_modules/@stdlib/array-int16/lib/polyfill.js","../node_modules/@stdlib/array-int16/lib/index.js","../node_modules/@stdlib/array-int16/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint16array/lib/main.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/main.js","../node_modules/@stdlib/array-uint16/lib/polyfill.js","../node_modules/@stdlib/array-uint16/lib/index.js","../node_modules/@stdlib/array-uint16/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/index.js","../node_modules/@stdlib/assert-is-int32array/lib/main.js","../node_modules/@stdlib/assert-has-int32array-support/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/main.js","../node_modules/@stdlib/constants-int32-min/lib/index.js","../node_modules/@stdlib/array-int32/lib/polyfill.js","../node_modules/@stdlib/array-int32/lib/index.js","../node_modules/@stdlib/array-int32/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint32array/lib/main.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/main.js","../node_modules/@stdlib/array-uint32/lib/polyfill.js","../node_modules/@stdlib/array-uint32/lib/index.js","../node_modules/@stdlib/array-uint32/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float32array/lib/main.js","../node_modules/@stdlib/assert-has-float32array-support/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/main.js","../node_modules/@stdlib/array-float32/lib/polyfill.js","../node_modules/@stdlib/array-float32/lib/index.js","../node_modules/@stdlib/array-float32/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float64array/lib/main.js","../node_modules/@stdlib/assert-has-float64array-support/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/main.js","../node_modules/@stdlib/array-float64/lib/polyfill.js","../node_modules/@stdlib/array-float64/lib/index.js","../node_modules/@stdlib/array-float64/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/index.js","../node_modules/@stdlib/utils-copy/lib/typed_arrays.js","../node_modules/@stdlib/utils-copy/lib/deep_copy.js","../node_modules/@stdlib/utils-copy/lib/copy.js","../node_modules/@stdlib/utils-copy/lib/index.js","../node_modules/@stdlib/assert-is-object/lib/main.js","../node_modules/@stdlib/assert-is-plain-object/lib/main.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/validate.js","../node_modules/@stdlib/assert-is-plain-object/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/factory.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\nvar main = ( typeof Object.defineProperty === 'function' ) ? Object.defineProperty : null;\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar defineProperty = require( './define_property.js' );\n\n\n// MAIN //\n\n/**\n* Tests for `Object.defineProperty` support.\n*\n* @private\n* @returns {boolean} boolean indicating if an environment has `Object.defineProperty` support\n*\n* @example\n* var bool = hasDefinePropertySupport();\n* // returns \n*/\nfunction hasDefinePropertySupport() {\n\t// Test basic support...\n\ttry {\n\t\tdefineProperty( {}, 'x', {} );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasDefinePropertySupport;\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// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @name defineProperty\n* @type {Function}\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nvar defineProperty = Object.defineProperty;\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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/* eslint-disable no-underscore-dangle, no-proto */\n\n'use strict';\n\n// VARIABLES //\n\nvar objectProtoype = Object.prototype;\nvar toStr = objectProtoype.toString;\nvar defineGetter = objectProtoype.__defineGetter__;\nvar defineSetter = objectProtoype.__defineSetter__;\nvar lookupGetter = objectProtoype.__lookupGetter__;\nvar lookupSetter = objectProtoype.__lookupSetter__;\n\n\n// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @param {Object} obj - object on which to define the property\n* @param {string} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nfunction defineProperty( obj, prop, descriptor ) {\n\tvar prototype;\n\tvar hasValue;\n\tvar hasGet;\n\tvar hasSet;\n\n\tif ( typeof obj !== 'object' || obj === null || toStr.call( obj ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an object. Value: `' + obj + '`.' );\n\t}\n\tif ( typeof descriptor !== 'object' || descriptor === null || toStr.call( descriptor ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. Property descriptor must be an object. Value: `' + descriptor + '`.' );\n\t}\n\thasValue = ( 'value' in descriptor );\n\tif ( hasValue ) {\n\t\tif (\n\t\t\tlookupGetter.call( obj, prop ) ||\n\t\t\tlookupSetter.call( obj, prop )\n\t\t) {\n\t\t\t// Override `__proto__` to avoid touching inherited accessors:\n\t\t\tprototype = obj.__proto__;\n\t\t\tobj.__proto__ = objectProtoype;\n\n\t\t\t// Delete property as existing getters/setters prevent assigning value to specified property:\n\t\t\tdelete obj[ prop ];\n\t\t\tobj[ prop ] = descriptor.value;\n\n\t\t\t// Restore original prototype:\n\t\t\tobj.__proto__ = prototype;\n\t\t} else {\n\t\t\tobj[ prop ] = descriptor.value;\n\t\t}\n\t}\n\thasGet = ( 'get' in descriptor );\n\thasSet = ( 'set' in descriptor );\n\n\tif ( hasValue && ( hasGet || hasSet ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.' );\n\t}\n\n\tif ( hasGet && defineGetter ) {\n\t\tdefineGetter.call( obj, prop, descriptor.get );\n\t}\n\tif ( hasSet && defineSetter ) {\n\t\tdefineSetter.call( obj, prop, descriptor.set );\n\t}\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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* Define (or modify) an object property.\n*\n* @module @stdlib/utils-define-property\n*\n* @example\n* var defineProperty = require( '@stdlib/utils-define-property' );\n*\n* var obj = {};\n* defineProperty( obj, 'foo', {\n* 'value': 'bar',\n* 'writable': false,\n* 'configurable': false,\n* 'enumerable': false\n* });\n* obj.foo = 'boop'; // => throws\n*/\n\n// MODULES //\n\nvar hasDefinePropertySupport = require( './has_define_property_support.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar defineProperty;\nif ( hasDefinePropertySupport() ) {\n\tdefineProperty = builtin;\n} else {\n\tdefineProperty = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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\nvar defineProperty = require( '@stdlib/utils-define-property' );\n\n\n// MAIN //\n\n/**\n* Defines a non-enumerable read-only property.\n*\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setNonEnumerableReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Define a non-enumerable read-only property.\n*\n* @module @stdlib/utils-define-nonenumerable-read-only-property\n*\n* @example\n* var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\n*\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\n\n// MODULES //\n\nvar setNonEnumerableReadOnly = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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// MAIN //\n\n/**\n* Tests for native `Symbol` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Symbol` support\n*\n* @example\n* var bool = hasSymbolSupport();\n* // returns \n*/\nfunction hasSymbolSupport() {\n\treturn (\n\t\ttypeof Symbol === 'function' &&\n\t\ttypeof Symbol( 'foo' ) === 'symbol'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasSymbolSupport;\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\nvar hasSymbols = require( '@stdlib/assert-has-symbol-support' );\n\n\n// VARIABLES //\n\nvar FLG = hasSymbols();\n\n\n// MAIN //\n\n/**\n* Tests for native `toStringTag` support.\n*\n* @returns {boolean} boolean indicating if an environment has `toStringTag` support\n*\n* @example\n* var bool = hasToStringTagSupport();\n* // returns \n*/\nfunction hasToStringTagSupport() {\n\treturn ( FLG && typeof Symbol.toStringTag === 'symbol' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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* Test for native `toStringTag` support.\n*\n* @module @stdlib/assert-has-tostringtag-support\n*\n* @example\n* var hasToStringTagSupport = require( '@stdlib/assert-has-tostringtag-support' );\n*\n* var bool = hasToStringTagSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasToStringTagSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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// MAIN //\n\nvar toStr = Object.prototype.toString;\n\n\n// EXPORTS //\n\nmodule.exports = toStr;\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\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification (via the internal property `[[Class]]`) of an object.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\treturn toStr.call( v );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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// FUNCTIONS //\n\nvar has = Object.prototype.hasOwnProperty;\n\n\n// MAIN //\n\n/**\n* Tests if an object has a specified property.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object has a specified property\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'bap' );\n* // returns false\n*/\nfunction hasOwnProp( value, property ) {\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\treturn has.call( value, property );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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* Test whether an object has a specified property.\n*\n* @module @stdlib/assert-has-own-property\n*\n* @example\n* var hasOwnProp = require( '@stdlib/assert-has-own-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* bool = hasOwnProp( beep, 'bop' );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasOwnProp = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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// MAIN //\n\nvar toStrTag = ( typeof Symbol === 'function' ) ? Symbol.toStringTag : '';\n\n\n// EXPORTS //\n\nmodule.exports = toStrTag;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar toStringTag = require( './tostringtag.js' );\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification of an object in environments supporting `Symbol.toStringTag`.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\tvar isOwn;\n\tvar tag;\n\tvar out;\n\n\tif ( v === null || v === void 0 ) {\n\t\treturn toStr.call( v );\n\t}\n\ttag = v[ toStringTag ];\n\tisOwn = hasOwnProp( v, toStringTag );\n\n\t// Attempt to override the `toStringTag` property. For built-ins having a `Symbol.toStringTag` property (e.g., `JSON`, `Math`, etc), the `Symbol.toStringTag` property is read-only (e.g., , so we need to wrap in a `try/catch`.\n\ttry {\n\t\tv[ toStringTag ] = void 0;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn toStr.call( v );\n\t}\n\tout = toStr.call( v );\n\n\tif ( isOwn ) {\n\t\tv[ toStringTag ] = tag;\n\t} else {\n\t\tdelete v[ toStringTag ];\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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* Return a string value indicating a specification defined classification of an object.\n*\n* @module @stdlib/utils-native-class\n*\n* @example\n* var nativeClass = require( '@stdlib/utils-native-class' );\n*\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* function Beep() {\n* return this;\n* }\n* str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\n\n// MODULES //\n\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar builtin = require( './native_class.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar nativeClass;\nif ( hasToStringTag() ) {\n\tnativeClass = polyfill;\n} else {\n\tnativeClass = builtin;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to extract a string value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a string can be extracted\n*/\nfunction test( value ) {\n\ttry {\n\t\tvalueOf.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar valueOf = String.prototype.valueOf; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2valueof.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string object\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns false\n*/\nfunction isString( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof String ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object String]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a string\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*/\nfunction isString( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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* Test if a value is a string.\n*\n* @module @stdlib/assert-is-string\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' );\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 5 );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isObject;\n*\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 'beep' );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isString = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isString, 'isPrimitive', isPrimitive );\nsetReadOnly( isString, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// VARIABLES //\n\nvar RE_CHARS = /[-\\/\\\\^$*+?.()|[\\]{}]/g; // eslint-disable-line no-useless-escape\n\n\n// MAIN //\n\n/**\n* Escapes a regular expression string.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} first argument must be a string primitive\n* @returns {string} escaped string\n*\n* @example\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\nfunction rescape( str ) {\n\tvar len;\n\tvar s;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Check if the string starts with a forward slash...\n\tif ( str[ 0 ] === '/' ) {\n\t\t// Find the last forward slash...\n\t\tlen = str.length;\n\t\tfor ( i = len-1; i >= 0; i-- ) {\n\t\t\tif ( str[ i ] === '/' ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:\n\tif ( i === void 0 || i <= 0 ) {\n\t\treturn str.replace( RE_CHARS, '\\\\$&' );\n\t}\n\t// We need to de-construct the string...\n\ts = str.substring( 1, i );\n\n\t// Only escape the characters between the `/`:\n\ts = s.replace( RE_CHARS, '\\\\$&' );\n\n\t// Reassemble:\n\tstr = str[ 0 ] + s + str.substring( i );\n\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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* Escape a regular expression string or pattern.\n*\n* @module @stdlib/utils-escape-regexp-string\n*\n* @example\n* var rescape = require( '@stdlib/utils-escape-regexp-string' );\n*\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\n\n// MODULES //\n\nvar rescape = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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\nvar RE = /./;\n\n\n// EXPORTS //\n\nmodule.exports = RE;\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* Tests if a value is a boolean primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean primitive\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns false\n*/\nfunction isBoolean( value ) {\n\treturn ( typeof value === 'boolean' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Boolean.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean object\n*\n* @example\n* var bool = isBoolean( true );\n* // returns false\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Boolean ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Boolean]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a boolean\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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* Test if a value is a boolean.\n*\n* @module @stdlib/assert-is-boolean\n*\n* @example\n* var isBoolean = require( '@stdlib/assert-is-boolean' );\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* // Use interface to check for boolean primitives...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( true ) );\n* // returns false\n*\n* @example\n* // Use interface to check for boolean objects...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isObject;\n*\n* var bool = isBoolean( true );\n* // returns false\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isBoolean = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isBoolean, 'isPrimitive', isPrimitive );\nsetReadOnly( isBoolean, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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// MAIN //\n\n/**\n* Returns the global object using code generation.\n*\n* @private\n* @returns {Object} global object\n*/\nfunction getGlobal() {\n\treturn new Function( 'return this;' )(); // eslint-disable-line no-new-func\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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// MAIN //\n\nvar obj = ( typeof self === 'object' ) ? self : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof window === 'object' ) ? window : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof global === 'object' ) ? global : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar getThis = require( './codegen.js' );\nvar Self = require( './self.js' );\nvar Win = require( './window.js' );\nvar Global = require( './global.js' );\n\n\n// MAIN //\n\n/**\n* Returns the global object.\n*\n* ## Notes\n*\n* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.\n*\n* @param {boolean} [codegen=false] - boolean indicating whether to use code generation to resolve the global object\n* @throws {TypeError} must provide a boolean\n* @throws {Error} unable to resolve global object\n* @returns {Object} global object\n*\n* @example\n* var g = getGlobal();\n* // returns {...}\n*/\nfunction getGlobal( codegen ) {\n\tif ( arguments.length ) {\n\t\tif ( !isBoolean( codegen ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Must provide a boolean primitive. Value: `'+codegen+'`.' );\n\t\t}\n\t\tif ( codegen ) {\n\t\t\treturn getThis();\n\t\t}\n\t\t// Fall through...\n\t}\n\t// Case: browsers and web workers\n\tif ( Self ) {\n\t\treturn Self;\n\t}\n\t// Case: browsers\n\tif ( Win ) {\n\t\treturn Win;\n\t}\n\t// Case: Node.js\n\tif ( Global ) {\n\t\treturn Global;\n\t}\n\t// Case: unknown\n\tthrow new Error( 'unexpected error. Unable to resolve global object.' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar getGlobal = require( '@stdlib/utils-global' );\n\n\n// MAIN //\n\nvar root = getGlobal();\nvar nodeList = root.document && root.document.childNodes;\n\n\n// EXPORTS //\n\nmodule.exports = nodeList;\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* Return the global object.\n*\n* @module @stdlib/utils-global\n*\n* @example\n* var getGlobal = require( '@stdlib/utils-global' );\n*\n* var g = getGlobal();\n* // returns {...}\n*/\n\n// MODULES //\n\nvar getGlobal = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar typedarray = Int8Array; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = typedarray;\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\nvar RE = require( './fixtures/re.js' );\nvar nodeList = require( './fixtures/nodelist.js' );\nvar typedarray = require( './fixtures/typedarray.js' );\n\n\n// MAIN //\n\n/**\n* Checks whether a polyfill is needed when using the `typeof` operator.\n*\n* @private\n* @returns {boolean} boolean indicating whether a polyfill is needed\n*/\nfunction check() {\n\tif (\n\t\t// Chrome 1-12 returns 'function' for regular expression instances (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof):\n\t\ttypeof RE === 'function' ||\n\n\t\t// Safari 8 returns 'object' for typed array and weak map constructors (underscore #1929):\n\t\ttypeof typedarray === 'object' ||\n\n\t\t// PhantomJS 1.9 returns 'function' for `NodeList` instances (underscore #2236):\n\t\ttypeof nodeList === 'function'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\nfunction reFunctionName() {\n\treturn /^\\s*function\\s*([^(]*)/i;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @module @stdlib/regexp-function-name\n*\n* @example\n* var reFunctionName = require( '@stdlib/regexp-function-name' );\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reFunctionName = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reFunctionName, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\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\nvar reFunctionName = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Captures everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* Regular expression: `/^\\s*function\\s*([^(]*)/i`\n*\n* - `/^\\s*`\n* - Match zero or more spaces at beginning\n*\n* - `function`\n* - Match the word `function`\n*\n* - `\\s*`\n* - Match zero or more spaces after the word `function`\n*\n* - `()`\n* - Capture\n*\n* - `[^(]*`\n* - Match anything except a left parenthesis `(` zero or more times\n*\n* - `/i`\n* - ignore case\n*\n* @constant\n* @type {RegExp}\n* @default /^\\s*function\\s*([^(]*)/i\n*/\nvar RE_FUNCTION_NAME = reFunctionName();\n\n\n// EXPORTS //\n\nmodule.exports = RE_FUNCTION_NAME;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar f;\n\n\n// FUNCTIONS //\n\n/**\n* Tests if a value is an array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an array\n*\n* @example\n* var bool = isArray( [] );\n* // returns true\n*\n* @example\n* var bool = isArray( {} );\n* // returns false\n*/\nfunction isArray( value ) {\n\treturn ( nativeClass( value ) === '[object Array]' );\n}\n\n\n// MAIN //\n\nif ( Array.isArray ) {\n\tf = Array.isArray;\n} else {\n\tf = isArray;\n}\n\n\n// EXPORTS //\n\nmodule.exports = f;\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* Test if a value is an array.\n*\n* @module @stdlib/assert-is-array\n*\n* @example\n* var isArray = require( '@stdlib/assert-is-array' );\n*\n* var bool = isArray( [] );\n* // returns true\n*\n* bool = isArray( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isArray = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isArray;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Returns a function which tests if every element in an array passes a test condition.\n*\n* @param {Function} predicate - function to apply\n* @throws {TypeError} must provide a function\n* @returns {Function} an array function\n*\n* @example\n* var isOdd = require( '@stdlib/assert-is-odd' );\n*\n* var arr1 = [ 1, 3, 5, 7 ];\n* var arr2 = [ 3, 5, 8 ];\n*\n* var validate = arrayfcn( isOdd );\n*\n* var bool = validate( arr1 );\n* // returns true\n*\n* bool = validate( arr2 );\n* // returns false\n*/\nfunction arrayfcn( predicate ) {\n\tif ( typeof predicate !== 'function' ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a function. Value: `' + predicate + '`.' );\n\t}\n\treturn every;\n\n\t/**\n\t* Tests if every element in an array passes a test condition.\n\t*\n\t* @private\n\t* @param {*} value - value to test\n\t* @returns {boolean} boolean indicating whether a value is an array for which all elements pass a test condition\n\t*/\n\tfunction every( value ) {\n\t\tvar len;\n\t\tvar i;\n\t\tif ( !isArray( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tlen = value.length;\n\t\tif ( len === 0 ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( predicate( value[ i ] ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayfcn;\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* Tests if a value is object-like.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is object-like\n*\n* @example\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( [] );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( null );\n* // returns false\n*/\nfunction isObjectLike( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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* Test if a value is object-like.\n*\n* @module @stdlib/assert-is-object-like\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' );\n*\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* bool = isObjectLike( [] );\n* // returns true\n*\n* bool = isObjectLike( null );\n* // returns false\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' ).isObjectLikeArray;\n*\n* var bool = isObjectLike( [ {}, [] ] );\n* // returns true\n*\n* bool = isObjectLike( [ {}, '3.0' ] );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar arrayfun = require( '@stdlib/assert-tools-array-function' );\nvar isObjectLike = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( isObjectLike, 'isObjectLikeArray', arrayfun( isObjectLike ) );\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Buffer instance.\n*\n* @param {*} value - value to validate\n* @returns {boolean} boolean indicating if a value is a Buffer instance\n*\n* @example\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( new Buffer( [1,2,3,4] ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( {} );\n* // returns false\n*\n* @example\n* var v = isBuffer( [] );\n* // returns false\n*/\nfunction isBuffer( value ) {\n\treturn (\n\t\tisObjectLike( value ) &&\n\t\t(\n\t\t\t// eslint-disable-next-line no-underscore-dangle\n\t\t\tvalue._isBuffer || // for envs missing Object.prototype.constructor (e.g., Safari 5-7)\n\t\t\t(\n\t\t\t\tvalue.constructor &&\n\n\t\t\t\t// WARNING: `typeof` is not a foolproof check, as certain envs consider RegExp and NodeList instances to be functions\n\t\t\t\ttypeof value.constructor.isBuffer === 'function' &&\n\t\t\t\tvalue.constructor.isBuffer( value )\n\t\t\t)\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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* Test if a value is a Buffer instance.\n*\n* @module @stdlib/assert-is-buffer\n*\n* @example\n* var isBuffer = require( '@stdlib/assert-is-buffer' );\n*\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* v = isBuffer( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isBuffer = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar RE = require( '@stdlib/regexp-function-name' ).REGEXP;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\n\n\n// MAIN //\n\n/**\n* Determines the name of a value's constructor.\n*\n* @param {*} v - input value\n* @returns {string} name of a value's constructor\n*\n* @example\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* @example\n* var v = constructorName( 5 );\n* // returns 'Number'\n*\n* @example\n* var v = constructorName( null );\n* // returns 'Null'\n*\n* @example\n* var v = constructorName( undefined );\n* // returns 'Undefined'\n*\n* @example\n* var v = constructorName( function noop() {} );\n* // returns 'Function'\n*/\nfunction constructorName( v ) {\n\tvar match;\n\tvar name;\n\tvar ctor;\n\tname = nativeClass( v ).slice( 8, -1 );\n\tif ( (name === 'Object' || name === 'Error') && v.constructor ) {\n\t\tctor = v.constructor;\n\t\tif ( typeof ctor.name === 'string' ) {\n\t\t\treturn ctor.name;\n\t\t}\n\t\tmatch = RE.exec( ctor.toString() );\n\t\tif ( match ) {\n\t\t\treturn match[ 1 ];\n\t\t}\n\t}\n\tif ( isBuffer( v ) ) {\n\t\treturn 'Buffer';\n\t}\n\treturn name;\n}\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// NOTES //\n\n/*\n* Built-in `typeof` operator behavior:\n*\n* ```text\n* typeof null => 'object'\n* typeof undefined => 'undefined'\n* typeof 'a' => 'string'\n* typeof 5 => 'number'\n* typeof NaN => 'number'\n* typeof true => 'boolean'\n* typeof false => 'boolean'\n* typeof {} => 'object'\n* typeof [] => 'object'\n* typeof function foo(){} => 'function'\n* typeof function* foo(){} => 'object'\n* typeof Symbol() => 'symbol'\n* ```\n*\n*/\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\tvar type;\n\n\t// Address `typeof null` => `object` (see http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null):\n\tif ( v === null ) {\n\t\treturn 'null';\n\t}\n\ttype = typeof v;\n\n\t// If the `typeof` operator returned something other than `object`, we are done. Otherwise, we need to check for an internal class name or search for a constructor.\n\tif ( type === 'object' ) {\n\t\treturn ctorName( v ).toLowerCase();\n\t}\n\treturn type;\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine the name of a value's constructor.\n*\n* @module @stdlib/utils-constructor-name\n*\n* @example\n* var constructorName = require( '@stdlib/utils-constructor-name' );\n*\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* v = constructorName( {} );\n* // returns 'Object'\n*\n* v = constructorName( true );\n* // returns 'Boolean'\n*/\n\n// MODULES //\n\nvar constructorName = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\treturn ctorName( v ).toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine a value's type.\n*\n* @module @stdlib/utils-type-of\n*\n* @example\n* var typeOf = require( '@stdlib/utils-type-of' );\n*\n* var str = typeOf( 'a' );\n* // returns 'string'\n*\n* str = typeOf( 5 );\n* // returns 'number'\n*/\n\n// MODULES //\n\nvar usePolyfill = require( './check.js' );\nvar typeOf = require( './typeof.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main = ( usePolyfill() ) ? polyfill : typeOf;\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar typeOf = require( '@stdlib/utils-type-of' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a function.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a function\n*\n* @example\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\nfunction isFunction( value ) {\n\t// Note: cannot use `typeof` directly, as various browser engines incorrectly return `'function'` when operating on non-function objects, such as regular expressions and NodeLists.\n\treturn ( typeOf( value ) === 'function' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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* Test if a value is a function.\n*\n* @module @stdlib/assert-is-function\n*\n* @example\n* var isFunction = require( '@stdlib/assert-is-function' );\n*\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\n\n// MODULES //\n\nvar isFunction = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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\nvar exec = require( './exec.js' );\n\n\n// MAIN //\n\n/**\n* Attempts to call a `RegExp` method.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if able to call a `RegExp` method\n*/\nfunction test( value ) {\n\ttry {\n\t\texec.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar exec = RegExp.prototype.exec; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = exec;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2exec.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a regular expression.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a regular expression\n*\n* @example\n* var bool = isRegExp( /\\.+/ );\n* // returns true\n*\n* @example\n* var bool = isRegExp( {} );\n* // returns false\n*/\nfunction isRegExp( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof RegExp ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object RegExp]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isRegExp;\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\nvar rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument argument must be a string primitive or regular expression\n* @throws {TypeError} third argument must be a string primitive or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive or regular expression. Value: `' + search + '`.' );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( 'invalid argument. Third argument must be a string primitive or replacement function. Value: `' + newval + '`.' );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Constructor which returns a `Number` object.\n*\n* @module @stdlib/number-ctor\n*\n* @example\n* var Number = require( '@stdlib/number-ctor' );\n*\n* var v = new Number( 10.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar Number = require( './number.js' );\n\n\n// EXPORTS //\n\nmodule.exports = Number;\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// EXPORTS //\n\nmodule.exports = Number; // eslint-disable-line stdlib/require-globals\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Number.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar Number = require( '@stdlib/number-ctor' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\nfunction isNumber( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Number ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Number]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a number\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( null );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Test if a value is a number.\n*\n* @module @stdlib/assert-is-number\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' );\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( null );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isObject;\n*\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNumber, 'isPrimitive', isPrimitive );\nsetReadOnly( isNumber, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Double-precision floating-point positive infinity.\n*\n* @module @stdlib/constants-float64-pinf\n* @type {number}\n*\n* @example\n* var FLOAT64_PINF = require( '@stdlib/constants-float64-pinf' );\n* // returns Infinity\n*/\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point positive infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point positive infinity has the bit sequence\n*\n* ```binarystring\n* 0 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.POSITIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_PINF = Number.POSITIVE_INFINITY; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_PINF;\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* Double-precision floating-point negative infinity.\n*\n* @module @stdlib/constants-float64-ninf\n* @type {number}\n*\n* @example\n* var FLOAT64_NINF = require( '@stdlib/constants-float64-ninf' );\n* // returns -Infinity\n*/\n\n// MODULES //\n\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point negative infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point negative infinity has the bit sequence\n*\n* ```binarystring\n* 1 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.NEGATIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_NINF = Number.NEGATIVE_INFINITY;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_NINF;\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\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Tests if a finite double-precision floating-point number is an integer.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\treturn (floor(x) === x);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// TODO: implementation (?)\n\n/**\n* Rounds a double-precision floating-point number toward negative infinity.\n*\n* @param {number} x - input value\n* @returns {number} rounded value\n*\n* @example\n* var v = floor( -4.2 );\n* // returns -5.0\n*\n* @example\n* var v = floor( 9.99999 );\n* // returns 9.0\n*\n* @example\n* var v = floor( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = floor( NaN );\n* // returns NaN\n*/\nvar floor = Math.floor; // eslint-disable-line stdlib/no-builtin-math\n\n\n// EXPORTS //\n\nmodule.exports = floor;\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* Test if a finite double-precision floating-point number is an integer.\n*\n* @module @stdlib/math-base-assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/math-base-assert-is-integer' );\n*\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* bool = isInteger( 3.14 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isInteger = require( './is_integer.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar isInt = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests if a number primitive is an integer value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a number primitive is an integer value\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tvalue < PINF &&\n\t\tvalue > NINF &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having an integer value\n*\n* @example\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having an integer value\n*\n* @example\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an integer\n*\n* @example\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isInteger( -3.14 );\n* // returns false\n*\n* @example\n* var bool = isInteger( null );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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* Test if a value is an integer.\n*\n* @module @stdlib/assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/assert-is-integer' );\n*\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isInteger( -3.14 );\n* // returns false\n*\n* bool = isInteger( null );\n* // returns false\n*\n* @example\n* // Use interface to check for integer primitives...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n*\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*\n* @example\n* // Use interface to check for integer objects...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n*\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue.valueOf() >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a nonnegative integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a nonnegative integer\n*\n* @example\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( null );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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* Test if a value is a nonnegative integer.\n*\n* @module @stdlib/assert-is-nonnegative-integer\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' );\n*\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* bool = isNonNegativeInteger( null );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isObject;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNonNegativeInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isNonNegativeInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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// MAIN //\n\nvar getProto = Object.getPrototypeOf;\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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* Returns the value of the `__proto__` property.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {*} value of `__proto__` property\n*/\nfunction getProto( obj ) {\n\t// eslint-disable-next-line no-proto\n\treturn obj.__proto__;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar getProto = require( './proto.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {(Object|null)} prototype\n*/\nfunction getPrototypeOf( obj ) {\n\tvar proto = getProto( obj );\n\tif ( proto || proto === null ) {\n\t\treturn proto;\n\t}\n\tif ( nativeClass( obj.constructor ) === '[object Function]' ) {\n\t\t// May break if the constructor has been tampered with...\n\t\treturn obj.constructor.prototype;\n\t}\n\tif ( obj instanceof Object ) {\n\t\treturn Object.prototype;\n\t}\n\t// Return `null` for objects created via `Object.create( null )`. Also return `null` for cross-realm objects on browsers that lack `__proto__` support, such as IE < 11.\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar builtin = require( './native.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar getProto;\nif ( isFunction( Object.getPrototypeOf ) ) {\n\tgetProto = builtin;\n} else {\n\tgetProto = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar getProto = require( './detect.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @param {*} value - input value\n* @returns {(Object|null)} prototype\n*\n* @example\n* var proto = getPrototypeOf( {} );\n* // returns {}\n*/\nfunction getPrototypeOf( value ) {\n\tif (\n\t\tvalue === null ||\n\t\tvalue === void 0\n\t) {\n\t\treturn null;\n\t}\n\t// In order to ensure consistent ES5/ES6 behavior, cast input value to an object (strings, numbers, booleans); ES5 `Object.getPrototypeOf` throws when provided primitives and ES6 `Object.getPrototypeOf` casts:\n\tvalue = Object( value );\n\n\treturn getProto( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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* Return the prototype of a provided object.\n*\n* @module @stdlib/utils-get-prototype-of\n*\n* @example\n* var getPrototype = require( '@stdlib/utils-get-prototype-of' );\n*\n* var proto = getPrototype( {} );\n* // returns {}\n*/\n\n// MODULES //\n\nvar getPrototype = require( './get_prototype_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getPrototype;\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\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an `Error` object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `Error` object\n*\n* @example\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isError( {} );\n* // returns false\n*/\nfunction isError( value ) {\n\tif ( typeof value !== 'object' || value === null ) {\n\t\treturn false;\n\t}\n\t// Check for `Error` objects from the same realm (same Node.js `vm` or same `Window` object)...\n\tif ( value instanceof Error ) {\n\t\treturn true;\n\t}\n\t// Walk the prototype tree until we find an object having the desired native class...\n\twhile ( value ) {\n\t\tif ( nativeClass( value ) === '[object Error]' ) {\n\t\t\treturn true;\n\t\t}\n\t\tvalue = getPrototypeOf( value );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isError;\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* Test if a value is an `Error` object.\n*\n* @module @stdlib/assert-is-error\n*\n* @example\n* var isError = require( '@stdlib/assert-is-error' );\n*\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* bool = isError( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isError = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isError;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to parse a regular expression string.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*/\nfunction reRegExp() {\n\treturn /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/; // eslint-disable-line no-useless-escape\n}\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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* Return a regular expression to parse a regular expression string.\n*\n* @module @stdlib/regexp-regexp\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var parts = RE_REGEXP.exec( '/^.*$/ig' );\n* // returns [ '/^.*$/ig', '^.*$', 'ig', 'index': 0, 'input': '/^.*$/ig' ]\n*/\n\n// MAIN //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reRegExp = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reRegExp, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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\nvar reRegExp = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Matches parts of a regular expression string.\n*\n* Regular expression: `/^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/`\n*\n* - `/^\\/`\n* - match a string that begins with a `/`\n*\n* - `()`\n* - capture\n*\n* - `(?:)+`\n* - capture, but do not remember, a group of characters which occur one or more times\n*\n* - `\\\\\\/`\n* - match the literal `\\/`\n*\n* - `|`\n* - OR\n*\n* - `[^\\/]`\n* - anything which is not the literal `\\/`\n*\n* - `\\/`\n* - match the literal `/`\n*\n* - `([imgy]*)`\n* - capture any characters matching `imgy` occurring zero or more times\n*\n* - `$/`\n* - string end\n*\n*\n* @constant\n* @type {RegExp}\n* @default /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/\n*/\nvar RE_REGEXP = reRegExp();\n\n\n// EXPORTS //\n\nmodule.exports = RE_REGEXP;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar reRegExp = require( '@stdlib/regexp-regexp' );\n\n\n// MAIN //\n\n/**\n* Parses a regular expression string and returns a new regular expression.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} must provide a regular expression string\n* @returns {(RegExp|null)} regular expression or null\n*\n* @example\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\nfunction reFromString( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Capture the regular expression pattern and any flags:\n\tstr = reRegExp().exec( str );\n\n\t// Create a new regular expression:\n\treturn ( str ) ? new RegExp( str[1], str[2] ) : null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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* Create a regular expression from a regular expression string.\n*\n* @module @stdlib/utils-regexp-from-string\n*\n* @example\n* var reFromString = require( '@stdlib/utils-regexp-from-string' );\n*\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\n\n// MODULES //\n\nvar reFromString = require( './from_string.js' );\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is `NaN`.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 7.0 );\n* // returns false\n*/\nfunction isnan( x ) {\n\treturn ( x !== x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a `NaN` number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a `NaN` number primitive\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a double-precision floating-point numeric value is `NaN`.\n*\n* @module @stdlib/math-base-assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/math-base-assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 7.0 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isnan = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a value of `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a value of `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( null );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a value is `NaN`.\n*\n* @module @stdlib/assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( null );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isObject;\n*\n* var bool = isnan( NaN );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isnan = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isnan, 'isPrimitive', isPrimitive );\nsetReadOnly( isnan, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a collection.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is a collection\n*\n* @example\n* var bool = isCollection( [] );\n* // returns true\n*\n* @example\n* var bool = isCollection( {} );\n* // returns false\n*/\nfunction isCollection( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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\nvar isnan = require( '@stdlib/assert-is-nan' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Returns the first index at which a given element can be found.\n*\n* @param {ArrayLike} arr - array-like object\n* @param {*} searchElement - element to find\n* @param {integer} [fromIndex] - starting index (if negative, the start index is determined relative to last element)\n* @throws {TypeError} must provide an array-like object\n* @throws {TypeError} `fromIndex` must be an integer\n* @returns {integer} index or -1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 5 );\n* // returns -1\n*\n* @example\n* // Using a `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* @example\n* // `fromIndex` which exceeds `array` length:\n* var arr = [ 1, 2, 3, 4, 2, 5 ];\n* var idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* @example\n* // Negative `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* var idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* @example\n* // Negative `fromIndex` exceeding input `array` length:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* @example\n* // Array-like objects:\n* var str = 'bebop';\n* var idx = indexOf( str, 'o' );\n* // returns 3\n*/\nfunction indexOf( arr, searchElement, fromIndex ) {\n\tvar len;\n\tvar i;\n\tif ( !isCollection( arr ) && !isString( arr ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array-like object. Value: `' + arr + '`.' );\n\t}\n\tlen = arr.length;\n\tif ( len === 0 ) {\n\t\treturn -1;\n\t}\n\tif ( arguments.length === 3 ) {\n\t\tif ( !isInteger( fromIndex ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `fromIndex` must be an integer. Value: `' + fromIndex + '`.' );\n\t\t}\n\t\tif ( fromIndex >= 0 ) {\n\t\t\tif ( fromIndex >= len ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\ti = fromIndex;\n\t\t} else {\n\t\t\ti = len + fromIndex;\n\t\t\tif ( i < 0 ) {\n\t\t\t\ti = 0;\n\t\t\t}\n\t\t}\n\t} else {\n\t\ti = 0;\n\t}\n\t// Check for `NaN`...\n\tif ( isnan( searchElement ) ) {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( isnan( arr[i] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( arr[ i ] === searchElement ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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* Maximum length of a typed array.\n*\n* @module @stdlib/constants-array-max-typed-array-length\n*\n* @example\n* var MAX_TYPED_ARRAY_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n* // returns 9007199254740991\n*/\n\n// MAIN //\n\n/**\n* Maximum length of a typed array.\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n*/\nvar MAX_TYPED_ARRAY_LENGTH = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = MAX_TYPED_ARRAY_LENGTH;\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* Return the first index at which a given element can be found.\n*\n* @module @stdlib/utils-index-of\n*\n* @example\n* var indexOf = require( '@stdlib/utils-index-of' );\n*\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* arr = [ 4, 3, 2, 1 ];\n* idx = indexOf( arr, 5 );\n* // returns -1\n*\n* // Using a `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* // `fromIndex` which exceeds `array` length:\n* arr = [ 1, 2, 3, 4, 2, 5 ];\n* idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* // Negative `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* // Negative `fromIndex` exceeding input `array` length:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* // Array-like objects:\n* var str = 'bebop';\n* idx = indexOf( str, 'o' );\n* // returns 3\n*/\n\n// MODULES //\n\nvar indexOf = require( './index_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.keys()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\treturn Object.keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar keys = require( './builtin.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests the built-in `Object.keys()` implementation when provided `arguments`.\n*\n* @private\n* @returns {boolean} boolean indicating whether the built-in implementation returns the expected number of keys\n*/\nfunction test() {\n\treturn ( keys( arguments ) || '' ).length !== 2;\n}\n\n\n// MAIN //\n\n/**\n* Tests whether the built-in `Object.keys()` implementation supports providing `arguments` as an input value.\n*\n* ## Notes\n*\n* - Safari 5.0 does **not** support `arguments` as an input value.\n*\n* @private\n* @returns {boolean} boolean indicating whether a built-in implementation supports `arguments`\n*/\nfunction check() {\n\treturn test( 1, 2 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\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// MAIN //\n\nvar bool = ( typeof Object.keys !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn ( nativeClass( value ) === '[object Arguments]' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( './main.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment returns the expected internal class of the `arguments` object.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment behaves as expected\n*\n* @example\n* var bool = detect();\n* // returns \n*/\nfunction detect() {\n\treturn isArguments( arguments );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnum = require( './native.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment has a bug where String indices are not detected as \"enumerable\" properties. Observed in Node v0.10.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment has the bug\n*/\nfunction detect() {\n\treturn !isEnum.call( 'beep', '0' );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @private\n* @name isEnumerableProperty\n* @type {Function}\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nvar isEnumerableProperty = Object.prototype.propertyIsEnumerable;\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar isString = require( '@stdlib/assert-is-string' );\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isEnum = require( './native.js' );\nvar hasStringEnumBug = require( './has_string_enumerability_bug.js' );\n\n\n// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nfunction isEnumerableProperty( value, property ) {\n\tvar bool;\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\tbool = isEnum.call( value, property );\n\tif ( !bool && hasStringEnumBug && isString( value ) ) {\n\t\t// Note: we only check for indices, as properties attached to a `String` object are properly detected as enumerable above.\n\t\tproperty = +property;\n\t\treturn (\n\t\t\t!isnan( property ) &&\n\t\t\tisInteger( property ) &&\n\t\t\tproperty >= 0 &&\n\t\t\tproperty < value.length\n\t\t);\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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* Test whether an object's own property is enumerable.\n*\n* @module @stdlib/assert-is-enumerable-property\n*\n* @example\n* var isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\n\n// MODULES //\n\nvar isEnumerableProperty = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-uint32-max' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object' &&\n\t\t!isArray( value ) &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH &&\n\t\thasOwnProp( value, 'callee' ) &&\n\t\t!isEnumerableProperty( value, 'callee' )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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* Test if a value is an `arguments` object.\n*\n* @module @stdlib/assert-is-arguments\n*\n* @example\n* var isArguments = require( '@stdlib/assert-is-arguments' );\n*\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* bool = isArguments( [] );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasArgumentsClass = require( './detect.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar isArguments;\nif ( hasArgumentsClass ) {\n\tisArguments = main;\n} else {\n\tisArguments = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar builtin = require( './builtin.js' );\n\n\n// VARIABLES //\n\nvar slice = Array.prototype.slice;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tif ( isArguments( value ) ) {\n\t\treturn builtin( slice.call( value ) );\n\t}\n\treturn builtin( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* No operation.\n*\n* @example\n* noop();\n* // ...does nothing.\n*/\nfunction noop() {\n\t// Empty function...\n}\n\n\n// EXPORTS //\n\nmodule.exports = noop;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar noop = require( '@stdlib/utils-noop' );\n\n\n// MAIN //\n\n// Note: certain environments treat an object's prototype as enumerable, which, as a matter of convention, it shouldn't be...\nvar bool = isEnumerableProperty( noop, 'prototype' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n\n\n// VARIABLES //\n\nvar obj = {\n\t'toString': null\n};\n\n\n// MAIN //\n\n// Note: certain environments don't allow enumeration of overwritten properties which are considered non-enumerable...\nvar bool = !isEnumerableProperty( obj, 'toString' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests whether a value equals the prototype of its constructor.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction isConstructorPrototype( value ) {\n\treturn ( value.constructor && value.constructor.prototype === value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isConstructorPrototype;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar EXCLUDED_KEYS = require( './excluded_keys.json' );\nvar win = require( './window.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Determines whether an environment throws when comparing to the prototype of a value's constructor (e.g., [IE9][1]).\n*\n* [1]: https://stackoverflow.com/questions/7688070/why-is-comparing-the-constructor-property-of-two-windows-unreliable\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment is buggy\n*/\nfunction check() {\n\tvar k;\n\tif ( typeOf( win ) === 'undefined' ) {\n\t\treturn false;\n\t}\n\tfor ( k in win ) { // eslint-disable-line guard-for-in\n\t\ttry {\n\t\t\tif (\n\t\t\t\tindexOf( EXCLUDED_KEYS, k ) === -1 &&\n\t\t\t\thasOwnProp( win, k ) &&\n\t\t\t\twin[ k ] !== null &&\n\t\t\t\ttypeOf( win[ k ] ) === 'object'\n\t\t\t) {\n\t\t\t\tisConstructorPrototype( win[ k ] );\n\t\t\t}\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// MAIN //\n\nbool = check();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\nvar w = ( typeof window === 'undefined' ) ? void 0 : window;\n\n\n// EXPORTS //\n\nmodule.exports = w;\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// MAIN //\n\nvar bool = ( typeof window !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar hasAutomationEqualityBug = require( './has_automation_equality_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar HAS_WINDOW = require( './has_window.js' );\n\n\n// MAIN //\n\n/**\n* Wraps the test for constructor prototype equality to accommodate buggy environments (e.g., environments which throw when testing equality).\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction wrapper( value ) {\n\tif ( HAS_WINDOW === false && !hasAutomationEqualityBug ) {\n\t\treturn isConstructorPrototype( value );\n\t}\n\ttry {\n\t\treturn isConstructorPrototype( value );\n\t} catch ( error ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = wrapper;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar HAS_ENUM_PROTO_BUG = require( './has_enumerable_prototype_bug.js' );\nvar HAS_NON_ENUM_PROPS_BUG = require( './has_non_enumerable_properties_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype_wrapper.js' );\nvar NON_ENUMERABLE = require( './non_enumerable.json' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tvar skipConstructor;\n\tvar skipPrototype;\n\tvar isFcn;\n\tvar out;\n\tvar k;\n\tvar p;\n\tvar i;\n\n\tout = [];\n\tif ( isArguments( value ) ) {\n\t\t// Account for environments which treat `arguments` differently...\n\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\tout.push( i.toString() );\n\t\t}\n\t\t// Note: yes, we are precluding the `arguments` array-like object from having other enumerable properties; however, this should (1) be very rare and (2) not be encouraged (e.g., doing something like `arguments.a = 'b'`; in certain engines directly manipulating the `arguments` value results in automatic de-optimization).\n\t\treturn out;\n\t}\n\tif ( typeof value === 'string' ) {\n\t\t// Account for environments which do not treat string character indices as \"own\" properties...\n\t\tif ( value.length > 0 && !hasOwnProp( value, '0' ) ) {\n\t\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\t\tout.push( i.toString() );\n\t\t\t}\n\t\t}\n\t} else {\n\t\tisFcn = ( typeof value === 'function' );\n\t\tif ( isFcn === false && !isObjectLike( value ) ) {\n\t\t\treturn out;\n\t\t}\n\t\tskipPrototype = ( HAS_ENUM_PROTO_BUG && isFcn );\n\t}\n\tfor ( k in value ) {\n\t\tif ( !( skipPrototype && k === 'prototype' ) && hasOwnProp( value, k ) ) {\n\t\t\tout.push( String( k ) );\n\t\t}\n\t}\n\tif ( HAS_NON_ENUM_PROPS_BUG ) {\n\t\tskipConstructor = isConstructorPrototype( value );\n\t\tfor ( i = 0; i < NON_ENUMERABLE.length; i++ ) {\n\t\t\tp = NON_ENUMERABLE[ i ];\n\t\t\tif ( !( skipConstructor && p === 'constructor' ) && hasOwnProp( value, p ) ) {\n\t\t\t\tout.push( String( p ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar hasArgumentsBug = require( './has_arguments_bug.js' );\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar wrapper = require( './builtin_wrapper.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @name keys\n* @type {Function}\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nvar keys;\nif ( HAS_BUILTIN ) {\n\tif ( hasArgumentsBug() ) {\n\t\tkeys = wrapper;\n\t} else {\n\t\tkeys = builtin;\n\t}\n} else {\n\tkeys = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* Return an array of an object's own enumerable property names.\n*\n* @module @stdlib/utils-keys\n*\n* @example\n* var keys = require( '@stdlib/utils-keys' );\n*\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\n\n// MODULES //\n\nvar keys = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyNames !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyNames = Object.getOwnPropertyNames;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn propertyNames( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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\nvar keys = require( '@stdlib/utils-keys' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n* - In environments lacking support for `Object.getOwnPropertyNames()`, property descriptors are unavailable, and thus all properties can be safely assumed to be enumerable. Hence, we can defer to calling `Object.keys`, which retrieves all own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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* Return an array of an object's own enumerable and non-enumerable property names.\n*\n* @module @stdlib/utils-property-names\n*\n* @example\n* var getOwnPropertyNames = require( '@stdlib/utils-property-names' );\n*\n* var keys = getOwnPropertyNames({\n* 'foo': 'bar',\n* 'beep': 'boop'\n* });\n* // e.g., returns [ 'foo', 'beep' ]\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyDescriptor !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyDescriptor = Object.getOwnPropertyDescriptor;\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tvar desc;\n\tif ( value === null || value === void 0 ) {\n\t\treturn null;\n\t}\n\tdesc = propertyDescriptor( value, property );\n\treturn ( desc === void 0 ) ? null : desc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n* - In environments lacking `Object.getOwnPropertyDescriptor()` support, property descriptors do not exist. In non-supporting environment, if an object has a provided property, this function returns a descriptor object equivalent to that returned in a supporting environment; otherwise, the function returns `null`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tif ( hasOwnProp( value, property ) ) {\n\t\treturn {\n\t\t\t'configurable': true,\n\t\t\t'enumerable': true,\n\t\t\t'writable': true,\n\t\t\t'value': value[ property ]\n\t\t};\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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* Return a property descriptor for an object's own property.\n*\n* @module @stdlib/utils-property-descriptor\n*\n* @example\n* var getOwnPropertyDescriptor = require( '@stdlib/utils-property-descriptor' );\n*\n* var obj = {\n* 'foo': 'bar',\n* 'beep': 'boop'\n* };\n*\n* var keys = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':'bar'}\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar main = ( typeof Buffer === 'function' ) ? Buffer : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar GlobalBuffer = require( './buffer.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Buffer` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Buffer` support\n*\n* @example\n* var bool = hasNodeBufferSupport();\n* // returns \n*/\nfunction hasNodeBufferSupport() {\n\tvar bool;\n\tvar b;\n\n\tif ( typeof GlobalBuffer !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tif ( typeof GlobalBuffer.from === 'function' ) {\n\t\t\tb = GlobalBuffer.from( [ 1, 2, 3, 4 ] );\n\t\t} else {\n\t\t\tb = new GlobalBuffer( [ 1, 2, 3, 4 ] ); // Note: this is deprecated behavior starting in Node v6 (see https://nodejs.org/api/buffer.html#buffer_new_buffer_array)\n\t\t}\n\t\tbool = (\n\t\t\tisBuffer( b ) &&\n\t\t\tb[ 0 ] === 1 &&\n\t\t\tb[ 1 ] === 2 &&\n\t\t\tb[ 2 ] === 3 &&\n\t\t\tb[ 3 ] === 4\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasNodeBufferSupport;\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* Test for native `Buffer` support.\n*\n* @module @stdlib/assert-has-node-buffer-support\n*\n* @example\n* var hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\n*\n* var bool = hasNodeBufferSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasNodeBufferSupport;\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// TODO: write (browser) polyfill\n\n// MAIN //\n\n/**\n* Buffer constructor.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Buffer constructor.\n*\n* @module @stdlib/buffer-ctor\n*\n* @example\n* var ctor = require( '@stdlib/buffer-ctor' );\n*\n* var b = new ctor( [ 1, 2, 3, 4 ] );\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\nvar main = require( './buffer.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasNodeBufferSupport() ) {\n\tctor = main;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = require( 'buffer' ).Buffer; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\nvar bool = isFunction( Buffer.from );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn Buffer.from( buffer );\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn new Buffer( buffer ); // eslint-disable-line no-buffer-constructor\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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* Copy buffer data to a new `Buffer` instance.\n*\n* @module @stdlib/buffer-from-buffer\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n* var copyBuffer = require( '@stdlib/buffer-from-buffer' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = copyBuffer( b1 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFrom = require( './has_from.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar copyBuffer;\nif ( hasFrom ) {\n\tcopyBuffer = main;\n} else {\n\tcopyBuffer = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt8Array = ( typeof Int8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int8Array\n*\n* @example\n* var bool = isInt8Array( new Int8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt8Array( [] );\n* // returns false\n*/\nfunction isInt8Array( value ) {\n\treturn (\n\t\t( hasInt8Array && value instanceof Int8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt8Array;\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// MAIN //\n\nvar main = ( typeof Int8Array === 'function' ) ? Int8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt8Array = require( '@stdlib/assert-is-int8array' );\nvar INT8_MAX = require( '@stdlib/constants-int8-max' );\nvar INT8_MIN = require( '@stdlib/constants-int8-min' );\nvar GlobalInt8Array = require( './int8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int8Array` support\n*\n* @example\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\nfunction hasInt8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt8Array( [ 1, 3.14, -3.14, INT8_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT8_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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* Minimum signed 8-bit integer.\n*\n* @module @stdlib/constants-int8-min\n* @type {integer32}\n*\n* @example\n* var INT8_MIN = require( '@stdlib/constants-int8-min' );\n* // returns -128\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 8-bit integer.\n*\n* ## Notes\n*\n* The number is given by\n*\n* ```tex\n* -(2^{7})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -128\n*/\nvar INT8_MIN = -128|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT8_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int8\n*\n* @example\n* var ctor = require( '@stdlib/array-int8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\nvar builtin = require( './int8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int8Array === 'function' ) ? Int8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int8Array` support.\n*\n* @module @stdlib/assert-has-int8array-support\n*\n* @example\n* var hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\n*\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8Array = ( typeof Uint8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8Array\n*\n* @example\n* var bool = isUint8Array( new Uint8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8Array( [] );\n* // returns false\n*/\nfunction isUint8Array( value ) {\n\treturn (\n\t\t( hasUint8Array && value instanceof Uint8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8Array;\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// MAIN //\n\nvar main = ( typeof Uint8Array === 'function' ) ? Uint8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8Array = require( '@stdlib/assert-is-uint8array' );\nvar UINT8_MAX = require( '@stdlib/constants-uint8-max' );\nvar GlobalUint8Array = require( './uint8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8Array` support\n*\n* @example\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\nfunction hasUint8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT8_MAX+1, UINT8_MAX+2 ];\n\t\tarr = new GlobalUint8Array( arr );\n\t\tbool = (\n\t\t\tisUint8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT8_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint8\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\nvar builtin = require( './uint8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8Array === 'function' ) ? Uint8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8Array` support.\n*\n* @module @stdlib/assert-has-uint8array-support\n*\n* @example\n* var hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\n*\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8ClampedArray = ( typeof Uint8ClampedArray === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8ClampedArray.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8ClampedArray\n*\n* @example\n* var bool = isUint8ClampedArray( new Uint8ClampedArray( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8ClampedArray( [] );\n* // returns false\n*/\nfunction isUint8ClampedArray( value ) {\n\treturn (\n\t\t( hasUint8ClampedArray && value instanceof Uint8ClampedArray ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8ClampedArray]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8ClampedArray;\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// MAIN //\n\nvar main = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8ClampedArray = require( '@stdlib/assert-is-uint8clampedarray' );\nvar GlobalUint8ClampedArray = require( './uint8clampedarray.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8ClampedArray` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8ClampedArray` support\n*\n* @example\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\nfunction hasUint8ClampedArraySupport() { // eslint-disable-line id-length\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8ClampedArray !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalUint8ClampedArray( [ -1, 0, 1, 3.14, 4.99, 255, 256 ] );\n\t\tbool = (\n\t\t\tisUint8ClampedArray( arr ) &&\n\t\t\tarr[ 0 ] === 0 && // clamped\n\t\t\tarr[ 1 ] === 0 &&\n\t\t\tarr[ 2 ] === 1 &&\n\t\t\tarr[ 3 ] === 3 && // round to nearest\n\t\t\tarr[ 4 ] === 5 && // round to nearest\n\t\t\tarr[ 5 ] === 255 &&\n\t\t\tarr[ 6 ] === 255 // clamped\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @module @stdlib/array-uint8c\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8c' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' ); // eslint-disable-line id-length\nvar builtin = require( './uint8clampedarray.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ClampedArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8ClampedArray` support.\n*\n* @module @stdlib/assert-has-uint8clampedarray-support\n*\n* @example\n* var hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' );\n*\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt16Array = ( typeof Int16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int16Array\n*\n* @example\n* var bool = isInt16Array( new Int16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt16Array( [] );\n* // returns false\n*/\nfunction isInt16Array( value ) {\n\treturn (\n\t\t( hasInt16Array && value instanceof Int16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt16Array;\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// MAIN //\n\nvar main = ( typeof Int16Array === 'function' ) ? Int16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt16Array = require( '@stdlib/assert-is-int16array' );\nvar INT16_MAX = require( '@stdlib/constants-int16-max' );\nvar INT16_MIN = require( '@stdlib/constants-int16-min' );\nvar GlobalInt16Array = require( './int16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int16Array` support\n*\n* @example\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\nfunction hasInt16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt16Array( [ 1, 3.14, -3.14, INT16_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT16_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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* Minimum signed 16-bit integer.\n*\n* @module @stdlib/constants-int16-min\n* @type {integer32}\n*\n* @example\n* var INT16_MIN = require( '@stdlib/constants-int16-min' );\n* // returns -32768\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 16-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{15})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 1000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -32768\n*/\nvar INT16_MIN = -32768|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT16_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int16\n*\n* @example\n* var ctor = require( '@stdlib/array-int16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\nvar builtin = require( './int16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int16Array === 'function' ) ? Int16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int16Array` support.\n*\n* @module @stdlib/assert-has-int16array-support\n*\n* @example\n* var hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\n*\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint16Array = ( typeof Uint16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint16Array\n*\n* @example\n* var bool = isUint16Array( new Uint16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint16Array( [] );\n* // returns false\n*/\nfunction isUint16Array( value ) {\n\treturn (\n\t\t( hasUint16Array && value instanceof Uint16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint16Array;\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// MAIN //\n\nvar main = ( typeof Uint16Array === 'function' ) ? Uint16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint16Array = require( '@stdlib/assert-is-uint16array' );\nvar UINT16_MAX = require( '@stdlib/constants-uint16-max' );\nvar GlobalUint16Array = require( './uint16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint16Array` support\n*\n* @example\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\nfunction hasUint16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT16_MAX+1, UINT16_MAX+2 ];\n\t\tarr = new GlobalUint16Array( arr );\n\t\tbool = (\n\t\t\tisUint16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT16_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 16-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint16\n*\n* @example\n* var ctor = require( '@stdlib/array-uint16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\nvar builtin = require( './uint16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint16Array === 'function' ) ? Uint16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint16Array` support.\n*\n* @module @stdlib/assert-has-uint16array-support\n*\n* @example\n* var hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\n*\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt32Array = ( typeof Int32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int32Array\n*\n* @example\n* var bool = isInt32Array( new Int32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt32Array( [] );\n* // returns false\n*/\nfunction isInt32Array( value ) {\n\treturn (\n\t\t( hasInt32Array && value instanceof Int32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt32Array;\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// MAIN //\n\nvar main = ( typeof Int32Array === 'function' ) ? Int32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt32Array = require( '@stdlib/assert-is-int32array' );\nvar INT32_MAX = require( '@stdlib/constants-int32-max' );\nvar INT32_MIN = require( '@stdlib/constants-int32-min' );\nvar GlobalInt32Array = require( './int32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int32Array` support\n*\n* @example\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\nfunction hasInt32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt32Array( [ 1, 3.14, -3.14, INT32_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT32_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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* Minimum signed 32-bit integer.\n*\n* @module @stdlib/constants-int32-min\n* @type {integer32}\n*\n* @example\n* var INT32_MIN = require( '@stdlib/constants-int32-min' );\n* // returns -2147483648\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 32-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{31})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -2147483648\n*/\nvar INT32_MIN = -2147483648|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT32_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int32\n*\n* @example\n* var ctor = require( '@stdlib/array-int32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\nvar builtin = require( './int32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int32Array === 'function' ) ? Int32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int32Array` support.\n*\n* @module @stdlib/assert-has-int32array-support\n*\n* @example\n* var hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\n*\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint32Array = ( typeof Uint32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint32Array\n*\n* @example\n* var bool = isUint32Array( new Uint32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint32Array( [] );\n* // returns false\n*/\nfunction isUint32Array( value ) {\n\treturn (\n\t\t( hasUint32Array && value instanceof Uint32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint32Array;\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// MAIN //\n\nvar main = ( typeof Uint32Array === 'function' ) ? Uint32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint32Array = require( '@stdlib/assert-is-uint32array' );\nvar UINT32_MAX = require( '@stdlib/constants-uint32-max' );\nvar GlobalUint32Array = require( './uint32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint32Array` support\n*\n* @example\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\nfunction hasUint32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT32_MAX+1, UINT32_MAX+2 ];\n\t\tarr = new GlobalUint32Array( arr );\n\t\tbool = (\n\t\t\tisUint32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT32_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 32-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint32\n*\n* @example\n* var ctor = require( '@stdlib/array-uint32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\nvar builtin = require( './uint32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint32Array === 'function' ) ? Uint32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint32Array` support.\n*\n* @module @stdlib/assert-has-uint32array-support\n*\n* @example\n* var hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\n*\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat32Array = ( typeof Float32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float32Array\n*\n* @example\n* var bool = isFloat32Array( new Float32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat32Array( [] );\n* // returns false\n*/\nfunction isFloat32Array( value ) {\n\treturn (\n\t\t( hasFloat32Array && value instanceof Float32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat32Array;\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// MAIN //\n\nvar main = ( typeof Float32Array === 'function' ) ? Float32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat32Array = require( '@stdlib/assert-is-float32array' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar GlobalFloat32Array = require( './float32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float32Array` support\n*\n* @example\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\nfunction hasFloat32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat32Array( [ 1.0, 3.14, -3.14, 5.0e40 ] );\n\t\tbool = (\n\t\t\tisFloat32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.140000104904175 &&\n\t\t\tarr[ 2 ] === -3.140000104904175 &&\n\t\t\tarr[ 3 ] === PINF\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of single-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float32\n*\n* @example\n* var ctor = require( '@stdlib/array-float32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\nvar builtin = require( './float32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float32Array === 'function' ) ? Float32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float32Array` support.\n*\n* @module @stdlib/assert-has-float32array-support\n*\n* @example\n* var hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\n*\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat64Array = ( typeof Float64Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float64Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float64Array\n*\n* @example\n* var bool = isFloat64Array( new Float64Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat64Array( [] );\n* // returns false\n*/\nfunction isFloat64Array( value ) {\n\treturn (\n\t\t( hasFloat64Array && value instanceof Float64Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float64Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat64Array;\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// MAIN //\n\nvar main = ( typeof Float64Array === 'function' ) ? Float64Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat64Array = require( '@stdlib/assert-is-float64array' );\nvar GlobalFloat64Array = require( './float64array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float64Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float64Array` support\n*\n* @example\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\nfunction hasFloat64ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat64Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat64Array( [ 1.0, 3.14, -3.14, NaN ] );\n\t\tbool = (\n\t\t\tisFloat64Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.14 &&\n\t\t\tarr[ 2 ] === -3.14 &&\n\t\t\tarr[ 3 ] !== arr[ 3 ]\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of double-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float64\n*\n* @example\n* var ctor = require( '@stdlib/array-float64' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\nvar builtin = require( './float64array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat64ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float64Array === 'function' ) ? Float64Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float64Array` support.\n*\n* @module @stdlib/assert-has-float64array-support\n*\n* @example\n* var hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\n*\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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\nvar Int8Array = require( '@stdlib/array-int8' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar Uint8ClampedArray = require( '@stdlib/array-uint8c' );\nvar Int16Array = require( '@stdlib/array-int16' );\nvar Uint16Array = require( '@stdlib/array-uint16' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar Uint32Array = require( '@stdlib/array-uint32' );\nvar Float32Array = require( '@stdlib/array-float32' );\nvar Float64Array = require( '@stdlib/array-float64' );\n\n\n// VARIABLES //\n\nvar hash;\n\n\n// FUNCTIONS //\n\n/**\n* Copies an `Int8Array`.\n*\n* @private\n* @param {Int8Array} arr - array to copy\n* @returns {Int8Array} new array\n*/\nfunction int8array( arr ) {\n\treturn new Int8Array( arr );\n}\n\n/**\n* Copies a `Uint8Array`.\n*\n* @private\n* @param {Uint8Array} arr - array to copy\n* @returns {Uint8Array} new array\n*/\nfunction uint8array( arr ) {\n\treturn new Uint8Array( arr );\n}\n\n/**\n* Copies a `Uint8ClampedArray`.\n*\n* @private\n* @param {Uint8ClampedArray} arr - array to copy\n* @returns {Uint8ClampedArray} new array\n*/\nfunction uint8clampedarray( arr ) {\n\treturn new Uint8ClampedArray( arr );\n}\n\n/**\n* Copies an `Int16Array`.\n*\n* @private\n* @param {Int16Array} arr - array to copy\n* @returns {Int16Array} new array\n*/\nfunction int16array( arr ) {\n\treturn new Int16Array( arr );\n}\n\n/**\n* Copies a `Uint16Array`.\n*\n* @private\n* @param {Uint16Array} arr - array to copy\n* @returns {Uint16Array} new array\n*/\nfunction uint16array( arr ) {\n\treturn new Uint16Array( arr );\n}\n\n/**\n* Copies an `Int32Array`.\n*\n* @private\n* @param {Int32Array} arr - array to copy\n* @returns {Int32Array} new array\n*/\nfunction int32array( arr ) {\n\treturn new Int32Array( arr );\n}\n\n/**\n* Copies a `Uint32Array`.\n*\n* @private\n* @param {Uint32Array} arr - array to copy\n* @returns {Uint32Array} new array\n*/\nfunction uint32array( arr ) {\n\treturn new Uint32Array( arr );\n}\n\n/**\n* Copies a `Float32Array`.\n*\n* @private\n* @param {Float32Array} arr - array to copy\n* @returns {Float32Array} new array\n*/\nfunction float32array( arr ) {\n\treturn new Float32Array( arr );\n}\n\n/**\n* Copies a `Float64Array`.\n*\n* @private\n* @param {Float64Array} arr - array to copy\n* @returns {Float64Array} new array\n*/\nfunction float64array( arr ) {\n\treturn new Float64Array( arr );\n}\n\n/**\n* Returns a hash of functions for copying typed arrays.\n*\n* @private\n* @returns {Object} function hash\n*/\nfunction typedarrays() {\n\tvar out = {\n\t\t'int8array': int8array,\n\t\t'uint8array': uint8array,\n\t\t'uint8clampedarray': uint8clampedarray,\n\t\t'int16array': int16array,\n\t\t'uint16array': uint16array,\n\t\t'int32array': int32array,\n\t\t'uint32array': uint32array,\n\t\t'float32array': float32array,\n\t\t'float64array': float64array\n\t};\n\treturn out;\n}\n\n\n// MAIN //\n\nhash = typedarrays();\n\n\n// EXPORTS //\n\nmodule.exports = hash;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar regexp = require( '@stdlib/utils-regexp-from-string' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar propertyNames = require( '@stdlib/utils-property-names' );\nvar propertyDescriptor = require( '@stdlib/utils-property-descriptor' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar defineProperty = require( '@stdlib/utils-define-property' );\nvar copyBuffer = require( '@stdlib/buffer-from-buffer' );\nvar typedArrays = require( './typed_arrays.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Clones a class instance.\n*\n* ## Notes\n*\n* - This should **only** be used for simple cases. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This approach should be considered **fragile**.\n* - The function is greedy, disregarding the notion of a `level`. Instead, the function deep copies all properties, as we assume the concept of `level` applies only to the class instance reference but not to its internal state. This prevents, in theory, two instances from sharing state.\n*\n*\n* @private\n* @param {Object} val - class instance\n* @returns {Object} new instance\n*/\nfunction cloneInstance( val ) {\n\tvar cache;\n\tvar names;\n\tvar name;\n\tvar refs;\n\tvar desc;\n\tvar tmp;\n\tvar ref;\n\tvar i;\n\n\tcache = [];\n\trefs = [];\n\n\tref = Object.create( getPrototypeOf( val ) );\n\tcache.push( val );\n\trefs.push( ref );\n\n\tnames = propertyNames( val );\n\tfor ( i = 0; i < names.length; i++ ) {\n\t\tname = names[ i ];\n\t\tdesc = propertyDescriptor( val, name );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( val[name] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( val[name], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( ref, name, desc );\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( ref );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( ref );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( ref );\n\t}\n\treturn ref;\n}\n\n/**\n* Copies an error object.\n*\n* @private\n* @param {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error - error to copy\n* @returns {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error copy\n*\n* @example\n* var err1 = new TypeError( 'beep' );\n*\n* var err2 = copyError( err1 );\n* // returns \n*/\nfunction copyError( error ) {\n\tvar cache = [];\n\tvar refs = [];\n\tvar keys;\n\tvar desc;\n\tvar tmp;\n\tvar key;\n\tvar err;\n\tvar i;\n\n\t// Create a new error...\n\terr = new error.constructor( error.message );\n\n\tcache.push( error );\n\trefs.push( err );\n\n\t// If a `stack` property is present, copy it over...\n\tif ( error.stack ) {\n\t\terr.stack = error.stack;\n\t}\n\t// Node.js specific (system errors)...\n\tif ( error.code ) {\n\t\terr.code = error.code;\n\t}\n\tif ( error.errno ) {\n\t\terr.errno = error.errno;\n\t}\n\tif ( error.syscall ) {\n\t\terr.syscall = error.syscall;\n\t}\n\t// Any enumerable properties...\n\tkeys = objectKeys( error );\n\tfor ( i = 0; i < keys.length; i++ ) {\n\t\tkey = keys[ i ];\n\t\tdesc = propertyDescriptor( error, key );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( error[ key ] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( error[ key ], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( err, key, desc );\n\t}\n\treturn err;\n}\n\n\n// MAIN //\n\n/**\n* Recursively performs a deep copy of an input object.\n*\n* @private\n* @param {*} val - value to copy\n* @param {(Array|Object)} copy - copy\n* @param {Array} cache - an array of visited objects\n* @param {Array} refs - an array of object references\n* @param {NonNegativeInteger} level - copy depth\n* @returns {*} deep copy\n*/\nfunction deepCopy( val, copy, cache, refs, level ) {\n\tvar parent;\n\tvar keys;\n\tvar name;\n\tvar desc;\n\tvar ctor;\n\tvar key;\n\tvar ref;\n\tvar x;\n\tvar i;\n\tvar j;\n\n\tlevel -= 1;\n\n\t// Primitives and functions...\n\tif (\n\t\ttypeof val !== 'object' ||\n\t\tval === null\n\t) {\n\t\treturn val;\n\t}\n\tif ( isBuffer( val ) ) {\n\t\treturn copyBuffer( val );\n\t}\n\tif ( isError( val ) ) {\n\t\treturn copyError( val );\n\t}\n\t// Objects...\n\tname = typeOf( val );\n\n\tif ( name === 'date' ) {\n\t\treturn new Date( +val );\n\t}\n\tif ( name === 'regexp' ) {\n\t\treturn regexp( val.toString() );\n\t}\n\tif ( name === 'set' ) {\n\t\treturn new Set( val );\n\t}\n\tif ( name === 'map' ) {\n\t\treturn new Map( val );\n\t}\n\tif (\n\t\tname === 'string' ||\n\t\tname === 'boolean' ||\n\t\tname === 'number'\n\t) {\n\t\t// If provided an `Object`, return an equivalent primitive!\n\t\treturn val.valueOf();\n\t}\n\tctor = typedArrays[ name ];\n\tif ( ctor ) {\n\t\treturn ctor( val );\n\t}\n\t// Class instances...\n\tif (\n\t\tname !== 'array' &&\n\t\tname !== 'object'\n\t) {\n\t\t// Cloning requires ES5 or higher...\n\t\tif ( typeof Object.freeze === 'function' ) {\n\t\t\treturn cloneInstance( val );\n\t\t}\n\t\treturn {};\n\t}\n\t// Arrays and plain objects...\n\tkeys = objectKeys( val );\n\tif ( level > 0 ) {\n\t\tparent = name;\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tx = val[ key ];\n\n\t\t\t// Primitive, Buffer, special class instance...\n\t\t\tname = typeOf( x );\n\t\t\tif (\n\t\t\t\ttypeof x !== 'object' ||\n\t\t\t\tx === null ||\n\t\t\t\t(\n\t\t\t\t\tname !== 'array' &&\n\t\t\t\t\tname !== 'object'\n\t\t\t\t) ||\n\t\t\t\tisBuffer( x )\n\t\t\t) {\n\t\t\t\tif ( parent === 'object' ) {\n\t\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\t\tdesc.value = deepCopy( x );\n\t\t\t\t\t}\n\t\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t\t} else {\n\t\t\t\t\tcopy[ key ] = deepCopy( x );\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Circular reference...\n\t\t\ti = indexOf( cache, x );\n\t\t\tif ( i !== -1 ) {\n\t\t\t\tcopy[ key ] = refs[ i ];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Plain array or object...\n\t\t\tref = ( isArray( x ) ) ? new Array( x.length ) : {};\n\t\t\tcache.push( x );\n\t\t\trefs.push( ref );\n\t\t\tif ( parent === 'array' ) {\n\t\t\t\tcopy[ key ] = deepCopy( x, ref, cache, refs, level );\n\t\t\t} else {\n\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\tdesc.value = deepCopy( x, ref, cache, refs, level );\n\t\t\t\t}\n\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t}\n\t\t}\n\t} else if ( name === 'array' ) {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tcopy[ key ] = val[ key ];\n\t\t}\n\t} else {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\tdefineProperty( copy, key, desc );\n\t\t}\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( copy );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( copy );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( copy );\n\t}\n\treturn copy;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepCopy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar deepCopy = require( './deep_copy.js' );\n\n\n// MAIN //\n\n/**\n* Copies or deep clones a value to an arbitrary depth.\n*\n* @param {*} value - value to copy\n* @param {NonNegativeInteger} [level=+infinity] - copy depth\n* @throws {TypeError} `level` must be a nonnegative integer\n* @returns {*} value copy\n*\n* @example\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\nfunction copy( value, level ) {\n\tvar out;\n\tif ( arguments.length > 1 ) {\n\t\tif ( !isNonNegativeInteger( level ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `level` must be a nonnegative integer. Value: `' + level + '`.' );\n\t\t}\n\t\tif ( level === 0 ) {\n\t\t\treturn value;\n\t\t}\n\t} else {\n\t\tlevel = PINF;\n\t}\n\tout = ( isArray( value ) ) ? new Array( value.length ) : {};\n\treturn deepCopy( value, out, [value], [out], level );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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* Copy or deep clone a value to an arbitrary depth.\n*\n* @module @stdlib/utils-copy\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ {'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\n\n// MODULES //\n\nvar copy = require( './copy.js' );\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an object; e.g., `{}`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an object\n*\n* @example\n* var bool = isObject( {} );\n* // returns true\n*\n* @example\n* var bool = isObject( null );\n* // returns false\n*/\nfunction isObject( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t!isArray( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObject;\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\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar objectPrototype = Object.prototype;\n\n\n// FUNCTIONS //\n\n/**\n* Tests that an object only has own properties.\n*\n* @private\n* @param {Object} obj - value to test\n* @returns {boolean} boolean indicating if an object only has own properties\n*/\nfunction ownProps( obj ) {\n\tvar key;\n\n\t// NOTE: possibility of perf boost if key enumeration order is known (see http://stackoverflow.com/questions/18531624/isplainobject-thing).\n\tfor ( key in obj ) {\n\t\tif ( !hasOwnProp( obj, key ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n\n// MAIN //\n\n/**\n* Tests if a value is a plain object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a plain object\n*\n* @example\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* @example\n* var bool = isPlainObject( null );\n* // returns false\n*/\nfunction isPlainObject( value ) {\n\tvar proto;\n\n\t// Screen for obvious non-objects...\n\tif ( !isObject( value ) ) {\n\t\treturn false;\n\t}\n\t// Objects with no prototype (e.g., `Object.create( null )`) are plain...\n\tproto = getPrototypeOf( value );\n\tif ( !proto ) {\n\t\treturn true;\n\t}\n\t// Objects having a prototype are plain if and only if they are constructed with a global `Object` function and the prototype points to the prototype of a plain object...\n\treturn (\n\t\t// Cannot have own `constructor` property:\n\t\t!hasOwnProp( value, 'constructor' ) &&\n\n\t\t// Prototype `constructor` property must be a function (see also https://bugs.jquery.com/ticket/9897 and http://stackoverflow.com/questions/18531624/isplainobject-thing):\n\t\thasOwnProp( proto, 'constructor' ) &&\n\t\tisFunction( proto.constructor ) &&\n\t\tnativeClass( proto.constructor ) === '[object Function]' &&\n\n\t\t// Test for object-specific method:\n\t\thasOwnProp( proto, 'isPrototypeOf' ) &&\n\t\tisFunction( proto.isPrototypeOf ) &&\n\n\t\t(\n\t\t\t// Test if the prototype matches the global `Object` prototype (same realm):\n\t\t\tproto === objectPrototype ||\n\n\t\t\t// Test that all properties are own properties (cross-realm; *most* likely a plain object):\n\t\t\townProps( value )\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - options to validate\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {(Error|null)} error object or null\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );\n\t}\n\tif ( hasOwnProp( options, 'url' ) ) {\n\t\topts.url = options.url;\n\t\tif ( !isString( opts.url ) ) {\n\t\t\treturn new TypeError( 'invalid option. `url` option must be a string primitive. Option: `' + opts.url + '`.' );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'message' ) ) {\n\t\topts.message = options.message;\n\t\tif ( !isString( opts.message ) ) {\n\t\t\treturn new TypeError( 'invalid option. `message` option must be a string primitive. Option: `' + opts.message + '`.' );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\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* Test if a value is a plain object.\n*\n* @module @stdlib/assert-is-plain-object\n*\n* @example\n* var isPlainObject = require( '@stdlib/assert-is-plain-object' );\n*\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* bool = isPlainObject( null );\n* // returns false\n*/\n\n// MODULES //\n\nvar isPlainObject = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar replace = require( '@stdlib/string-replace' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Returns a function which formats an error message for production.\n*\n* @param {Options} options - function options\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {Function} error formatting function\n*\n* @example\n* var opts = {\n* 'url': 'https://stdlib.io/error-decoder.html'\n* };\n*\n* var fcn = factory( opts );\n* // returns \n*/\nfunction factory( options ) {\n\tvar opts;\n\tvar err;\n\topts = copy( defaults );\n\terr = validate( opts, options );\n\tif ( err ) {\n\t\tthrow err;\n\t}\n\treturn formatProdErrorMessage;\n\n\t/**\n\t* Formats an error message for production.\n\t*\n\t* @private\n\t* @param {string} code - error code\n\t* @param {*} ...args - error message arguments\n\t* @returns {string} formatted error message\n\t*/\n\tfunction formatProdErrorMessage() {\n\t\tvar code = arguments[ 0 ];\n\t\tvar url = opts.url + '?code='+code;\n\t\tvar msg;\n\t\tvar i;\n\t\tfor ( i = 1; i < arguments.length; i++ ) {\n\t\t\turl += '&arg[]=' + encodeURIComponent( arguments[ i ] );\n\t\t}\n\t\tmsg = replace( opts.message, '{{url}}', url );\n\t\tmsg = replace( msg, '{{code}}', code );\n\t\treturn msg;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Format an error message for production.\n*\n* @module @stdlib/error-tools-fmtprodmsg\n*\n* @example\n* var formatProdErrorMessage = require( '@stdlib/error-tools-fmtprodmsg' );\n*\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar formatProdErrorMessage = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( formatProdErrorMessage, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @name formatProdErrorMessage\n* @type {Function}\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\nvar formatProdErrorMessage = factory( defaults );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["defineProperty","Object","has_define_property_support","err","builtin","objectProtoype","prototype","toStr","toString","defineGetter","__defineGetter__","defineSetter","__defineSetter__","lookupGetter","__lookupGetter__","lookupSetter","__lookupSetter__","polyfill","obj","prop","descriptor","hasValue","hasGet","hasSet","call","TypeError","__proto__","value","Error","get","set","require$$1","require$$2","lib","require$$0","main","configurable","enumerable","writable","primitive","FLG","Symbol","hasSymbols","toStringTag","tostring","native_class","v","has","hasOwnProperty","property","toStrTag","hasOwnProp","isOwn","tag","out","valueOf","String","nativeClass","test","object","isPrimitive","isObject","setReadOnly","isString","require$$3","RE_CHARS","str","s","i","length","replace","substring","re","Boolean","isBoolean","codegen","Function","self_1","self","window_1","window","global","module","exports","getThis","Self","Win","Global","arguments","root","nodeList","document","childNodes","typedarray","Int8Array","RE","check_1","reFunctionName","Array","isArray","isObjectLike","predicate","len","arrayfun","_isBuffer","constructor","isBuffer","REGEXP","match","name","ctor","slice","exec","ctorName","typeOf","type","toLowerCase","RegExp","rescape","isFunction","isRegExp","search","newval","Number","isNumber","POSITIVE_INFINITY","NEGATIVE_INFINITY","floor","Math","x","PINF","NINF","isInt","integer","isInteger","isNonNegativeInteger","getProto","getPrototypeOf","proto","reRegExp","isNan","isnan","isCollection","index_of","arr","searchElement","fromIndex","keys","has_arguments_bug","has_builtin","bool","isArguments","bool$8","detect","detect_1","native","propertyIsEnumerable","bool$7","isEnum","hasStringEnumBug","isEnumerableProperty","require$$4","builtin_wrapper","has_enumerable_prototype_bug","has_non_enumerable_properties_bug","is_constructor_prototype","w","indexOf","isConstructorPrototype","EXCLUDED_KEYS","win","bool$4","k","check","hasAutomationEqualityBug","HAS_WINDOW","HAS_ENUM_PROTO_BUG","HAS_NON_ENUM_PROPS_BUG","error","NON_ENUMERABLE","wrapper","skipConstructor","skipPrototype","isFcn","p","push","getOwnPropertyNames","propertyNames","getOwnPropertyDescriptor","propertyDescriptor","desc","Buffer","GlobalBuffer","b","from","buffer","hasInt8Array","isInt8Array","GlobalInt8Array","INT8_MAX","hasUint8Array","Uint8Array","isUint8Array","GlobalUint8Array","UINT8_MAX","hasUint8ClampedArray","Uint8ClampedArray","isUint8ClampedArray","GlobalUint8ClampedArray","hasInt16Array","Int16Array","isInt16Array","GlobalInt16Array","INT16_MAX","hasUint16Array","Uint16Array","isUint16Array","GlobalUint16Array","UINT16_MAX","hasInt32Array","Int32Array","isInt32Array","GlobalInt32Array","INT32_MAX","hasUint32Array","Uint32Array","isUint32Array","GlobalUint32Array","UINT32_MAX","hasFloat32Array","Float32Array","isFloat32Array","GlobalFloat32Array","hasFloat64Array","Float64Array","isFloat64Array","GlobalFloat64Array","NaN","require$$5","require$$6","require$$7","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","isError","regexp","objectKeys","require$$8","require$$9","require$$10","require$$11","copyBuffer","require$$12","typedArrays","deepCopy","val","copy","cache","refs","level","parent","key","ref","j","tmp","message","stack","code","errno","syscall","copyError","Date","Set","Map","freeze","names","create","isExtensible","preventExtensions","isSealed","seal","isFrozen","cloneInstance","copy_1","objectPrototype","isPrototypeOf","ownProps","validate","opts","options","url","defaults","factory_1","msg","encodeURIComponent","formatProdErrorMessage","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","RangeError","format"],"mappings":";6kBAsBA,ICAIA,EDA0C,mBAA1BC,OAAOD,eAAkCC,OAAOD,eAAiB,KC4BrF,IAAAE,EAbA,WAEC,IAEC,OADAF,EAAgB,GAAI,IAAK,KAClB,EACN,MAAQG,GACT,OAAO,ICiBTC,EALqBH,OAAOD,eC/BxBK,EAAiBJ,OAAOK,UACxBC,EAAQF,EAAeG,SACvBC,EAAeJ,EAAeK,iBAC9BC,EAAeN,EAAeO,iBAC9BC,EAAeR,EAAeS,iBAC9BC,EAAeV,EAAeW,iBAuFlC,IAAAC,EAnDA,SAAyBC,EAAKC,EAAMC,GACnC,IAAId,EACAe,EACAC,EACAC,EAEJ,GAAoB,iBAARL,GAA4B,OAARA,GAAsC,mBAAtBX,EAAMiB,KAAMN,GAC3D,MAAM,IAAIO,UAAW,+DAAiEP,EAAM,MAE7F,GAA2B,iBAAfE,GAA0C,OAAfA,GAAoD,mBAA7Bb,EAAMiB,KAAMJ,GACzE,MAAM,IAAIK,UAAW,oEAAsEL,EAAa,MAyBzG,IAvBAC,EAAa,UAAWD,KAGtBP,EAAaW,KAAMN,EAAKC,IACxBJ,EAAaS,KAAMN,EAAKC,IAGxBb,EAAYY,EAAIQ,UAChBR,EAAIQ,UAAYrB,SAGTa,EAAKC,GACZD,EAAKC,GAASC,EAAWO,MAGzBT,EAAIQ,UAAYpB,GAEhBY,EAAKC,GAASC,EAAWO,OAG3BL,EAAW,QAASF,EACpBG,EAAW,QAASH,EAEfC,IAAcC,GAAUC,GAC5B,MAAM,IAAIK,MAAO,wHASlB,OANKN,GAAUb,GACdA,EAAae,KAAMN,EAAKC,EAAMC,EAAWS,KAErCN,GAAUZ,GACdA,EAAaa,KAAMN,EAAKC,EAAMC,EAAWU,KAEnCZ,GCrEJd,EAAU2B,EACVd,EAAWe,EAefC,EAjB+BC,IASb9B,EAEAa,EC7BdjB,EAAiBkC,EAmCrB,IAAAC,EAZA,SAAmCjB,EAAKC,EAAMQ,GAC7C3B,EAAgBkB,EAAKC,EAAM,CAC1BiB,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,KCJXM,EAL+BC,ECA/B,IAAAK,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCMjB,ICdIa,EDIJ,WACC,MACmB,mBAAXC,QACoB,iBAApBA,OAAQ,OCPPC,GAqBV,ICTAT,EDEA,WACC,OAASO,GAAqC,iBAAvBC,OAAOE,aEf/BC,EALY3C,OAAOK,UAAUE,SCAzBD,EAAQ2B,EAiCZ,IAAAW,EAPA,SAAsBC,GACrB,OAAOvC,EAAMiB,KAAMsB,IC3BhBC,EAAM9C,OAAOK,UAAU0C,eAyC3B,ICjBAf,EDIA,SAAqBN,EAAOsB,GAC3B,OACCtB,SAKMoB,EAAIvB,KAAMG,EAAOsB,IEnCrBC,EAA+B,mBAAXT,OAA0BA,OAAOE,YAAc,GCAnEQ,EAAajB,EACbS,EDIaO,ECHb3C,EAAQyB,EAwDZ,ICpCI5B,EAAU2B,EACVd,EDKJ,SAAsB6B,GACrB,IAAIM,EACAC,EACAC,EAEJ,GAAKR,QACJ,OAAOvC,EAAMiB,KAAMsB,GAEpBO,EAAMP,EAAGH,GACTS,EAAQD,EAAYL,EAAGH,GAGvB,IACCG,EAAGH,QAAgB,EAClB,MAAQxC,GACT,OAAOI,EAAMiB,KAAMsB,GASpB,OAPAQ,EAAM/C,EAAMiB,KAAMsB,GAEbM,EACJN,EAAGH,GAAgBU,SAEZP,EAAGH,GAEJW,GCdRrB,EAjBqBC,IASNjB,EAEAb,EChCXmD,ECDUC,OAAOlD,UAAUiD,QDyB/B,IEvBIE,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADA4B,EAAQ/B,KAAMG,IACP,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB6B,SAGjBhB,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,EAAW9B,EA0Bf,ICSI+B,EAAc5B,EACd6B,EDjBJ,SAAmBpC,GAClB,OAASiC,EAAajC,IAAWkC,EAAUlC,ICkBxCkC,EAAWG,EAKfF,EAAaC,EAAU,cANL/B,GAOlB8B,EAAaC,EAAU,WAAYF,GAKnC,IAAA5B,EAAiB8B,EClDbA,EAAW7B,EAAsC0B,YAKjDK,EAAW,yBAqDf,ICzCAhC,EDIA,SAAkBiC,GACjB,IACIC,EACAC,EAEJ,IAAML,EAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAGrG,GAAkB,MAAbA,EAAK,GAGT,IAAME,EADAF,EAAIG,OACI,EAAGD,GAAK,GACH,MAAbF,EAAKE,GADcA,KAO1B,YAAW,IAANA,GAAgBA,GAAK,EAClBF,EAAII,QAASL,EAAU,SAM/BE,GAHAA,EAAID,EAAIK,UAAW,EAAGH,IAGhBE,QAASL,EAAU,QAGzBC,EAAMA,EAAK,GAAMC,EAAID,EAAIK,UAAWH,KE/CrCI,EALS,ICyBT,IAAAjC,EAPA,SAAoBZ,GACnB,MAA0B,kBAAVA,GCjBbnB,ECDWiE,QAAQnE,UAAUE,SDyBjC,IEvBIiD,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADAnB,EAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAoBhC,GACnB,MAAsB,iBAAVA,IACNA,aAAiB8C,UAGjBjC,EACGkB,EAAM/B,GAEoB,qBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,GAAW9B,EAkCf,ICAI+B,GAAc5B,EACdwC,GDRJ,SAAoB/C,GACnB,OAASiC,EAAajC,IAAWkC,GAAUlC,ICSxCkC,GAAWG,EAKfF,GAAaY,GAAW,cANN1C,GAOlB8B,GAAaY,GAAW,WAAYb,IAKpC,IAAA5B,GAAiByC,GCpCjB,IAAAC,GAPA,WACC,OAAO,IAAIC,SAAU,eAAd,ICFRC,GAL4B,iBAATC,KAAsBA,KAAO,KCKhDC,GAL8B,iBAAXC,OAAwBA,OAAS,6GCAhD9D,GAA0B,iBAAX+D,GAAwBA,GAAS,KAKpDC,OAAOC,QAAUjE,OCLbwD,GAAYxC,GAAuC0B,YACnDwB,GAAUrD,GACVsD,GAAOrD,GACPsD,GAAMtB,GACNuB,sCAkDJ,IAAApD,GA7BA,SAAoBwC,GACnB,GAAKa,UAAUnB,OAAS,CACvB,IAAMK,GAAWC,GAChB,MAAM,IAAIlD,UAAW,+DAA+DkD,EAAQ,MAE7F,GAAKA,EACJ,OAAOS,KAKT,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,MAAM,IAAI3D,MAAO,uDC3Cd6D,GCOYvD,KDNZwD,GAAWD,GAAKE,UAAYF,GAAKE,SAASC,WER1CC,GAAaC,UCEbC,GAAK7D,EACLwD,GHUaA,GGTbG,GDCaA,GC6BjB,IAAAG,GAnBA,WACC,MAEe,mBAAPD,IAGe,iBAAfF,IAGa,mBAAbH,ICST,IAAAvD,GAPA,WACC,MAAO,2BCEJ8D,GAAiBlE,GADHG,EAOL+D,GAAgB,SCjCR/D,MDsCrB,IAAAD,GAAiBgE,GEtCbxC,GAAcvB,EAwClB,ICpBAD,GDWKiE,MAAMC,QACND,MAAMC,QARX,SAAkBxE,GACjB,MAAkC,mBAAzB8B,GAAa9B,IEzBnBwE,GAAUjE,GC0Bd,ICGIkE,GDbJ,SAAuBzE,GACtB,OACW,OAAVA,GACiB,iBAAVA,GCQSO,EAOLkE,GAAc,oBFR3B,SAAmBC,GAClB,GAA0B,mBAAdA,EACX,MAAM,IAAI5E,UAAW,sDAAwD4E,EAAY,MAE1F,OASA,SAAgB1E,GACf,IAAI2E,EACAlC,EACJ,IAAM+B,GAASxE,GACd,OAAO,EAGR,GAAa,KADb2E,EAAM3E,EAAM0C,QAEX,OAAO,EAER,IAAMD,EAAI,EAAGA,EAAIkC,EAAKlC,IACrB,IAAiC,IAA5BiC,EAAW1E,EAAOyC,IACtB,OAAO,EAGT,OAAO,GEpBuCmC,CAAUH,KAK1D,IAAAnE,GAAiBmE,GCvCbA,GAAelE,GA+CnB,IC3BAD,GDOA,SAAmBN,GAClB,OACCyE,GAAczE,KAGbA,EAAM6E,WAEL7E,EAAM8E,aAGgC,mBAA/B9E,EAAM8E,YAAYC,UACzB/E,EAAM8E,YAAYC,SAAU/E,KEtC5B8B,GAAcvB,EACd6D,GAAKhE,GAA0C4E,OAC/CD,GAAW1E,GAuDf,IAAAG,GAxBA,SAA0BW,GACzB,IAAI8D,EACAC,EACAC,EAEJ,IAAe,YADfD,EAAOpD,GAAaX,GAAIiE,MAAO,GAAI,KACC,UAATF,IAAqB/D,EAAE2D,YAAc,CAE/D,GAA0B,iBAD1BK,EAAOhE,EAAE2D,aACQI,KAChB,OAAOC,EAAKD,KAGb,GADAD,EAAQb,GAAGiB,KAAMF,EAAKtG,YAErB,OAAOoG,EAAO,GAGhB,OAAKF,GAAU5D,GACP,SAED+D,GCnDJI,GCkBkB/E,GDmCtB,IErDI+E,GDkBkB/E,GCAtB,ICFIgF,GHkBJ,SAAiBpE,GAChB,IAAIqE,EAGJ,OAAW,OAANrE,EACG,OAKM,YAHdqE,SAAcrE,GAINmE,GAAUnE,GAAIsE,cAEfD,GG9BJlG,GDNJ,SAAiB6B,GAChB,OAAOmE,GAAUnE,GAAIsE,eCetBnF,GAZkBC,KAOajB,GAAWiG,GCtBtCA,GAAShF,GA2Bb,ICNAD,GDFA,SAAqBN,GAEpB,MAA6B,aAApBuF,GAAQvF,IErBdqF,GCFOK,OAAO/G,UAAU0G,KD0B5B,IEvBIvD,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADAqF,GAAKxF,KAAMG,IACJ,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBN,IA0CrB,IC1CIoF,GAAUpF,EACVqF,GAAaxF,GACbgC,GAAW/B,EAAsC4B,YACjD4D,GDuBJ,SAAmB7F,GAClB,MAAsB,iBAAVA,IACNA,aAAiB0F,SAGjB7E,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MC2BxB,ICvCAM,GDmBA,SAAkBiC,EAAKuD,EAAQC,GAC9B,IAAM3D,GAAUG,GACf,MAAM,IAAIzC,UAAW,wEAA0EyC,EAAM,MAEtG,GAAKH,GAAU0D,GACdA,EAASH,GAASG,GAClBA,EAAS,IAAIJ,OAAQI,EAAQ,UAEzB,IAAMD,GAAUC,GACpB,MAAM,IAAIhG,UAAW,+FAAiGgG,EAAS,MAEhI,IAAM1D,GAAU2D,KAAaH,GAAYG,GACxC,MAAM,IAAIjG,UAAW,gGAAkGiG,EAAS,MAEjI,OAAOxD,EAAII,QAASmD,EAAQC,IEhC7B,IAAAnF,GAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCAjBM,GCjBiB0F,OCAbnH,GCAS0B,GAMS5B,UAAUE,SDkBhC,IEvBIiD,GAAc1B,EACd4F,GAAS3F,GACT0B,GFSJ,SAAe/B,GACd,IAEC,OADAnB,GAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IETLqC,GARiBN,IA2CrB,IAAAyB,GAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiBgG,KAGjBnF,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MCnCpBiC,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd0F,GDfJ,SAAmBjG,GAClB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa8D,GAAU,cANL5F,IAOlB8B,GAAa8D,GAAU,WAAY/D,IAKnC,IAAA5B,GAAiB2F,GCvBjB3F,GALmB0F,OAAOE,kBCS1B5F,GA1BaC,GAqBa4F,kBChCtBC,GCsBQC,KAAKD,MDIjB,IENA9F,GFDA,SAAoBgG,GACnB,OAAQF,GAAME,KAAOA,GGpBlBC,GAAOhG,GACPiG,GAAOpG,GACPqG,GAAQpG,GAuBZ,IAAAqG,GAXA,SAAoB1G,GACnB,OACCA,EAAQuG,IACRvG,EAAQwG,IACRC,GAAOzG,IClBLiG,GAAW1F,GAAsC0B,YACjDwE,GAAQrG,GA6BZ,IAAAQ,GAVA,SAAoBZ,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,ICvBLiG,GAAW1F,GAAsC2B,SACjDuE,GAAQrG,GA6BZ,IAAA4B,GAVA,SAAoBhC,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICMI+B,GAAc5B,EACdoG,GDdJ,SAAoB3G,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICexCkC,GAAWG,GAKfF,GAAawE,GAAW,cANNtG,IAOlB8B,GAAawE,GAAW,WAAYzE,IAKpC,IAAA5B,GAAiBqG,GCvDbA,GAAYpG,GAAuC0B,YA6BvD,IAAArB,GAVA,SAA+BZ,GAC9B,OACC2G,GAAW3G,IACXA,GAAS,GCtBP2G,GAAYpG,GAAuC2B,SA6BvD,IAAAF,GAVA,SAA+BhC,GAC9B,OACC2G,GAAW3G,IACXA,EAAM4B,WAAa,GCtBjBK,GAAc1B,GACd2B,GAAW9B,GAsCf,ICGI+B,GAAc5B,EACdqG,GDXJ,SAA+B5G,GAC9B,OAASiC,GAAajC,IAAWkC,GAAUlC,ICYxCkC,GAAWG,GAKfF,GAAayE,GAAsB,cANjBvG,IAOlB8B,GAAayE,GAAsB,WAAY1E,IAK/C,IAAA5B,GAAiBsG,GCxDbC,GAAWvI,OAAOwI,eCatB,IAAAC,GARA,SAAmBxH,GAElB,OAAOA,EAAIQ,WCPR+B,GAAcvB,EACdsG,GAAWzG,GA+Bf,IAAAd,GAnBA,SAAyBC,GACxB,IAAIwH,EAAQF,GAAUtH,GACtB,OAAKwH,GAAmB,OAAVA,EACNA,EAEgC,sBAAnCjF,GAAavC,EAAIuF,aAEdvF,EAAIuF,YAAYnG,UAEnBY,aAAejB,OACZA,OAAOK,UAGR,MCzBJF,GHIaoI,GGHbvH,GAAWe,GCFXwG,GDAatG,GAQAjC,OAAOwI,gBACZrI,GAEAa,GCoBZ,ICdAgB,GDFA,SAAyBN,GACxB,OACCA,QAGO,MAGRA,EAAQ1B,OAAQ0B,GAET6G,GAAU7G,KEzBd8G,GAAiBvG,GACjBuB,GAAc1B,EAwClB,ICrBAE,GDAA,SAAkBN,GACjB,GAAsB,iBAAVA,GAAgC,OAAVA,EACjC,OAAO,EAGR,GAAKA,aAAiBC,MACrB,OAAO,EAGR,KAAQD,GAAQ,CACf,GAA8B,mBAAzB8B,GAAa9B,GACjB,OAAO,EAERA,EAAQ8G,GAAgB9G,GAEzB,OAAO,GEdR,IAAAQ,GAPA,WACC,MAAO,oCCWJwG,GAAW5G,GADGG,EAOLyG,GAAU,SChCRzG,UCAX6B,GAAW7B,EAAsC0B,YACjD+E,GFyCaA,GEXjB,ICdA1G,GDAA,SAAuBiC,GACtB,IAAMH,GAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAMrG,OAHAA,EAAMyE,KAAW3B,KAAM9C,IAGN,IAAImD,OAAQnD,EAAI,GAAIA,EAAI,IAAO,MEJjD,IAAA/B,GAPA,SAAgB8F,GACf,OAASA,GAAMA,GCfZL,GAAW1F,GAAsC0B,YACjDgF,GCcQ1G,GDmBZ,IAAAK,GAVA,SAAgBZ,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,IE3BLiG,GAAW1F,GAAsC2B,SACjD+E,GDcQ1G,GCeZ,IAAAyB,GAVA,SAAgBhC,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd2G,GDfJ,SAAgBlH,GACf,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa+E,GAAO,cANF7G,IAOlB8B,GAAa+E,GAAO,WAAYhF,IAKhC,IAAA5B,GAAiB4G,GCxDbP,GAAYpG,GAkChB,IClCI2G,GAAQ3G,GACR4G,GDmBJ,SAAuBnH,GACtB,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QENqB,kBDnBzBN,GAAW/B,EAAsC4B,YACjD0E,GAAYtE,GAAuCJ,YA0GvD,IAAAmF,GAhDA,SAAkBC,EAAKC,EAAeC,GACrC,IAAI5C,EACAlC,EACJ,IAAM0E,GAAcE,KAAUjF,GAAUiF,GACvC,MAAM,IAAIvH,UAAW,0EAA4EuH,EAAM,MAGxG,GAAa,KADb1C,EAAM0C,EAAI3E,QAET,OAAQ,EAET,GAA0B,IAArBmB,UAAUnB,OAAe,CAC7B,IAAMiE,GAAWY,GAChB,MAAM,IAAIzH,UAAW,6DAA+DyH,EAAY,MAEjG,GAAKA,GAAa,EAAI,CACrB,GAAKA,GAAa5C,EACjB,OAAQ,EAETlC,EAAI8E,OAEJ9E,EAAIkC,EAAM4C,GACD,IACR9E,EAAI,QAINA,EAAI,EAGL,GAAKyE,GAAOI,IACX,KAAQ7E,EAAIkC,EAAKlC,IAChB,GAAKyE,GAAOG,EAAI5E,IACf,OAAOA,OAIT,KAAQA,EAAIkC,EAAKlC,IAChB,GAAK4E,EAAK5E,KAAQ6E,EACjB,OAAO7E,EAIV,OAAQ,GErDTnC,GALcC,GClBd,IAAA9B,GAPA,SAAeuB,GACd,OAAO1B,OAAOkJ,KAAMlJ,OAAQ0B,KCrBzBwH,GAAOjH,GAmCX,IAAAkH,GAPA,WACC,OAlBD,WACC,OAA8C,KAArCD,GAAM3D,YAAe,IAAKnB,OAiB5BX,CAAM,EAAG,ICxBjB2F,QALoC,IAAhBpJ,OAAOkJ,KCAvB1F,GAAcvB,EA+BlB,IC1BIoH,GD0BJnH,GAPA,SAAsBR,GACrB,MAAkC,uBAAzB8B,GAAa9B,ICzBnB4H,GAAcrH,GA2BdsH,GAPJ,WACC,OAAOD,GAAa/D,WAMdiE,GAKP,IC3BIH,GD2BJI,GAAiBJ,GEDjBK,GAL2B1J,OAAOK,UAAUsJ,qBDHxCC,IAvBS3H,GAiBGV,KAAM,OAAQ,KAW9B,IE5BIuC,GAAW7B,EACX2G,GAAQ9G,GAAmC6B,YAC3C0E,GAAYtG,GAAuC4B,YACnDkG,GAAS9F,GACT+F,GFwBaT,GE6BjB,IAAAnH,GAzBA,SAA+BR,EAAOsB,GACrC,IAAIqG,EACJ,OACC3H,YAKD2H,EAAOQ,GAAOtI,KAAMG,EAAOsB,KACb8G,IAAoBhG,GAAUpC,IAIzCkH,GAFF5F,GAAYA,IAGXqF,GAAWrF,IACXA,GAAY,GACZA,EAAWtB,EAAM0C,OAGZiF,IC3BRrH,GAL2BC,GCnBvBiB,GAAajB,EACb8H,GAAuBjI,GACvBoE,GAAUnE,GACVsG,GAAYtE,GCiChB,IAAA/B,GAjBwBC,GACbH,GDQX,SAAsBJ,GACrB,OACW,OAAVA,GACiB,iBAAVA,IACNwE,GAASxE,IACc,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QAhCS4F,YAiCf9G,GAAYxB,EAAO,YAClBqI,GAAsBrI,EAAO,WEtC5B4H,GAAcrH,GACd9B,GAAU2B,GAKVgF,GAAQb,MAAM5F,UAAUyG,MA+B5B,IAAAmD,GAVA,SAAevI,GACd,OAAK4H,GAAa5H,GACVvB,GAAS2G,GAAMvF,KAAMG,IAEtBvB,GAASuB,ICnBjB,ICAAwI,GAZ2BjI,IDK3B,cCEuC,aCWvCkI,IAlB2BlI,GAKjB,CACT1B,SAAY,MAO0B,YCCvC,ICJI8I,GDIJe,GAPA,SAAiC1I,GAChC,OAASA,EAAM8E,aAAe9E,EAAM8E,YAAYnG,YAAcqB,GER3D2I,GAAwB,oBAAXtF,YAA2B,EAASA,ODAjD7B,GAAajB,EACbqI,GAAUxI,GACVmF,GAASlF,GACTwI,GAAyBxG,GACzByG,wPACAC,GCAaJ,GD2CbK,GAzBJ,WACC,IAAIC,EACJ,GAAuB,cAAlB1D,GAAQwD,IACZ,OAAO,EAER,IAAME,KAAKF,GACV,KAEmC,IAAjCH,GAASE,GAAeG,IACxBzH,GAAYuH,GAAKE,IACJ,OAAbF,GAAKE,IACkB,WAAvB1D,GAAQwD,GAAKE,KAEbJ,GAAwBE,GAAKE,IAE7B,MAAQzK,GACT,OAAO,EAGT,OAAO,EAMD0K,GAKP,IErDIvB,GAA2B,oBAAXtE,OCAhB8F,GHqDaxB,GGpDbkB,GAAyBzI,GACzBgJ,GDGazB,GCuBjB,IC5BIlD,GAAelE,GACfiB,GAAapB,EACbwH,GAAcvH,GACdgJ,GAAqBhH,GACrBiH,GAAyBhB,GACzBO,GDSJ,SAAkB7I,GACjB,IAAoB,IAAfoJ,KAAyBD,GAC7B,OAAON,GAAwB7I,GAEhC,IACC,OAAO6I,GAAwB7I,GAC9B,MAAQuJ,GACT,OAAO,ICfLC,iHAyEJ,IC7EI/K,GAAU4B,GACVoJ,GAAUpH,GACV/C,GDuBJ,SAAeU,GACd,IAAI0J,EACAC,EACAC,EACAjI,EACAsH,EACAY,EACApH,EAGJ,GADAd,EAAM,GACDiG,GAAa5H,GAAU,CAE3B,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,YAGb,OAAO8C,EAER,GAAsB,iBAAV3B,GAEX,GAAKA,EAAM0C,OAAS,IAAMlB,GAAYxB,EAAO,KAC5C,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,gBAGR,CAEN,IAAe,KADf+K,EAA2B,mBAAV5J,KACQyE,GAAczE,GACtC,OAAO2B,EAERgI,EAAkBN,IAAsBO,EAEzC,IAAMX,KAAKjJ,EACF2J,GAAuB,cAANV,IAAuBzH,GAAYxB,EAAOiJ,IAClEtH,EAAImI,KAAMjI,OAAQoH,IAGpB,GAAKK,GAEJ,IADAI,EAAkBb,GAAwB7I,GACpCyC,EAAI,EAAGA,EAAI+G,GAAe9G,OAAQD,IACvCoH,EAAIL,GAAgB/G,GACZiH,GAAyB,gBAANG,IAAyBrI,GAAYxB,EAAO6J,IACtElI,EAAImI,KAAMjI,OAAQgI,IAIrB,OAAOlI,GEnDRrB,GDrBkBF,GADIG,KA6BbkJ,GAEAhL,GAGDa,GE7BRoI,QALmD,IAA/BpJ,OAAOyL,oBCAvBC,GAAgB1L,OAAOyL,oBAgC3B,IChCIvC,GAAOjH,GCgCX,IAAAD,GAjBkBC,GFUlB,SAA8BP,GAC7B,OAAOgK,GAAe1L,OAAQ0B,KCA/B,SAA8BA,GAC7B,OAAOwH,GAAMlJ,OAAQ0B,KEtBtB0H,QALwD,IAApCpJ,OAAO2L,yBCAvBC,GAAqB5L,OAAO2L,yBAuChC,ICvCIzI,GAAajB,ECkCjB,IAAAD,GAjBkBC,GFUlB,SAAmCP,EAAOsB,GACzC,IAAI6I,EACJ,OAAKnK,cAIa,KADlBmK,EAAOD,GAAoBlK,EAAOsB,IAF1B,KAG4B6I,GCLrC,SAAmCnK,EAAOsB,GACzC,OAAKE,GAAYxB,EAAOsB,GAChB,CACNb,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,EAAOsB,IAGX,o4qBErCJd,GAA0C4J,GAK9C7G,OAAOC,QAAUhD,OCLbuE,GAAWxE,GACX8J,sCA4CJ,IAAA7J,GA9BA,WACC,IAAImH,EACA2C,EAEJ,GAA6B,mBAAjBD,GACX,OAAO,EAGR,IAEEC,EADiC,mBAAtBD,GAAaE,KACpBF,GAAaE,KAAM,CAAE,EAAG,EAAG,EAAG,IAE9B,IAAIF,GAAc,CAAE,EAAG,EAAG,EAAG,IAElC1C,EACC5C,GAAUuF,IACC,IAAXA,EAAG,IACQ,IAAXA,EAAG,IACQ,IAAXA,EAAG,IACQ,IAAXA,EAAG,GAEH,MAAQ9L,GACTmJ,GAAO,EAER,OAAOA,GCtBRrH,GAL2BC,GCE3B,ICDIC,SCb2B4J,ODc3B9K,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GAjB2BC,KASnBC,GAEAlB,GEjBJqI,GANapH,GACJH,GAKiBmK,MCN1BxF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAI,GAVA,SAAqBgK,GACpB,IAAMzF,GAAUyF,GACf,MAAM,IAAI1K,UAAW,oDAAsD0K,EAAS,KAErF,OAAOJ,GAAOG,KAAMC,IC1BjBzF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAd,GAVA,SAAqBkL,GACpB,IAAMzF,GAAUyF,GACf,MAAM,IAAI1K,UAAW,oDAAsD0K,EAAS,KAErF,OAAO,IAAIJ,GAAQI,ICOpBlK,GHtBiBqH,GGMNvH,GACIC,GClBXyB,GAAcvB,EAKdkK,GAAsC,mBAAdtG,UA6B5B,IClCI3D,GAA8B,mBAAd2D,UAA6BA,UAAY,KCAzDuG,GFwBJ,SAAsB1K,GACrB,OACGyK,IAAgBzK,aAAiBmE,WACV,uBAAzBrC,GAAa9B,IExBX2K,GDEanK,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAgC,mBAApBsD,GACX,OAAO,EAGR,IACCtD,EAAM,IAAIsD,GAAiB,CAAE,EAAG,MAAO,KAAMC,MAC7CjD,EACC+C,GAAarD,IACA,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEO,MDDZA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb8B,mBAAd0F,UAA6BA,eAAY,EDczD7E,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB0BC,KFSlB9B,GAEAa,GGvBJwC,GAAcvB,EAKdsK,GAAwC,mBAAfC,WA6B7B,IClCItK,GAA+B,mBAAfsK,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuB/K,GACtB,OACG6K,IAAiB7K,aAAiB8K,YACX,wBAAzBhJ,GAAa9B,IEzBXgL,GDGaxK,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB2D,GACX,OAAO,EAGR,IAEC3D,EAAM,IAAI2D,GADV3D,EAAM,CAAE,EAAG,MAAO,KAAM4D,IAAaA,MAErCtD,EACCoD,GAAc1D,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ4D,MAAb5D,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCb+B,mBAAfqM,WAA8BA,gBAAa,EDc3DxL,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd2K,GAAsD,mBAAtBC,kBA6BpC,IClCI3K,GAAsC,mBAAtB2K,kBAAqCA,kBAAoB,KCAzEC,GFwBJ,SAA8BpL,GAC7B,OACGkL,IAAwBlL,aAAiBmL,mBAClB,+BAAzBrJ,GAAa9B,IE1BXqL,GDIa7K,GCuCjB,IAAAA,GA7BA,WACC,IAAImH,EACAN,EAEJ,GAAwC,mBAA5BgE,GACX,OAAO,EAGR,IACChE,EAAM,IAAIgE,GAAyB,EAAG,EAAG,EAAG,EAAG,KAAM,KAAM,IAAK,MAChE1D,EACCyD,GAAqB/D,IACR,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,MAAbA,EAAK,IACQ,MAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbsC,mBAAtB0M,kBAAqCA,uBAAoB,EDczE7L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjBkCC,KFS1B9B,GAEAa,GGvBJwC,GAAcvB,EAKd+K,GAAwC,mBAAfC,WA6B7B,IClCI/K,GAA+B,mBAAf+K,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBxL,GACtB,OACGsL,IAAiBtL,aAAiBuL,YACX,wBAAzBzJ,GAAa9B,IExBXyL,GDEajL,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArBoE,GACX,OAAO,EAGR,IACCpE,EAAM,IAAIoE,GAAkB,CAAE,EAAG,MAAO,KAAMC,QAC9C/D,EACC6D,GAAcnE,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,QDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAf8M,WAA8BA,gBAAa,EDc3DjM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdoL,GAA0C,mBAAhBC,YA6B9B,IClCIpL,GAAgC,mBAAhBoL,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwB7L,GACvB,OACG2L,IAAkB3L,aAAiB4L,aACZ,yBAAzB9J,GAAa9B,IEzBX8L,GDGatL,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtByE,GACX,OAAO,EAGR,IAECzE,EAAM,IAAIyE,GADVzE,EAAM,CAAE,EAAG,MAAO,KAAM0E,MAAcA,QAEtCpE,EACCkE,GAAexE,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ0E,QAAb1E,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhBmN,YAA+BA,iBAAc,EDc7DtM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdyL,GAAwC,mBAAfC,WA6B7B,IClCIzL,GAA+B,mBAAfyL,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBlM,GACtB,OACGgM,IAAiBhM,aAAiBiM,YACX,wBAAzBnK,GAAa9B,IExBXmM,GDEa3L,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB8E,GACX,OAAO,EAGR,IACC9E,EAAM,IAAI8E,GAAkB,CAAE,EAAG,MAAO,KAAMC,aAC9CzE,EACCuE,GAAc7E,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,aDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAfwN,WAA8BA,gBAAa,EDc3D3M,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd8L,GAA0C,mBAAhBC,YA6B9B,IClCI9L,GAAgC,mBAAhB8L,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwBvM,GACvB,OACGqM,IAAkBrM,aAAiBsM,aACZ,yBAAzBxK,GAAa9B,IEzBXwM,GDGahM,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBmF,GACX,OAAO,EAGR,IAECnF,EAAM,IAAImF,GADVnF,EAAM,CAAE,EAAG,MAAO,KAAMoF,WAAcA,aAEtC9E,EACC4E,GAAelF,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQoF,aAAbpF,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhB6N,YAA+BA,iBAAc,EDc7DhN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdmM,GAA4C,mBAAjBC,aA6B/B,IClCInM,GAAiC,mBAAjBmM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB5M,GACxB,OACG0M,IAAmB1M,aAAiB2M,cACb,0BAAzB7K,GAAa9B,IE1BXuG,GAAOnG,GACPyM,GDGarM,GCqCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvBwF,GACX,OAAO,EAGR,IACCxF,EAAM,IAAIwF,GAAoB,CAAE,EAAK,MAAO,KAAM,OAClDlF,EACCiF,GAAgBvF,IACH,IAAbA,EAAK,IACQ,oBAAbA,EAAK,KACS,oBAAdA,EAAK,IACLA,EAAK,KAAQd,GAEb,MAAQ/H,GACTmJ,GAAO,EAER,OAAOA,GCtBR,ICDIlJ,GCbiC,mBAAjBkO,aAAgCA,kBAAe,EDc/DrN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB6BC,KFSrB9B,GAEAa,GGvBJwC,GAAcvB,EAKduM,GAA4C,mBAAjBC,aA6B/B,IClCIvM,GAAiC,mBAAjBuM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyBhN,GACxB,OACG8M,IAAmB9M,aAAiB+M,cACb,0BAAzBjL,GAAa9B,IE1BXiN,GDIazM,GCoCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvB4F,GACX,OAAO,EAGR,IACC5F,EAAM,IAAI4F,GAAoB,CAAE,EAAK,MAAO,KAAMC,MAClDvF,EACCqF,GAAgB3F,IACH,IAAbA,EAAK,IACQ,OAAbA,EAAK,KACS,OAAdA,EAAK,IACLA,EAAK,IAAQA,EAAK,GAElB,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCrBR,ICKIxC,GANA1G,GCbiC,mBAAjBsO,aAAgCA,kBAAe,EDc/DzN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCajBkF,GET4B5E,KFSrB9B,GAEAa,GAMR,IG7BI6E,GAAY5D,GACZuK,GAAa1K,GACb+K,GAAoB9K,GACpBkL,GAAalJ,GACbuJ,GAActD,GACd2D,GAAakB,GACbb,GAAcc,GACdT,GAAeU,GACfN,GHqBa5H,GGJjB,SAASmI,GAAWjG,GACnB,OAAO,IAAIlD,GAAWkD,GAUvB,SAASkG,GAAYlG,GACpB,OAAO,IAAIyD,GAAYzD,GAUxB,SAASmG,GAAmBnG,GAC3B,OAAO,IAAI8D,GAAmB9D,GAU/B,SAASoG,GAAYpG,GACpB,OAAO,IAAIkE,GAAYlE,GAUxB,SAASqG,GAAarG,GACrB,OAAO,IAAIuE,GAAavE,GAUzB,SAASsG,GAAYtG,GACpB,OAAO,IAAI4E,GAAY5E,GAUxB,SAASuG,GAAavG,GACrB,OAAO,IAAIiF,GAAajF,GAUzB,SAASwG,GAAcxG,GACtB,OAAO,IAAIsF,GAActF,GAU1B,SAASyG,GAAczG,GACtB,OAAO,IAAI0F,GAAc1F,GAgC1B,IClJI7F,GAAajB,EACbiE,GAAUpE,GACV2E,GAAW1E,GACX0N,GAAU1L,GACVkD,GAAS+C,GACT0F,GAASb,GACTvE,GAAUwE,GACVa,GAAaZ,GACbrD,GAAgBkE,GAChBhE,GAAqBiE,GACrBrH,GAAiBsH,GACjB/P,GAAiBgQ,EACjBC,GAAaC,GACbC,GD+GO,CACTlB,UAAaA,GACbC,WAAcA,GACdC,kBAAqBA,GACrBC,WAAcA,GACdC,YAAeA,GACfC,WAAcA,GACdC,YAAeA,GACfC,aAAgBA,GAChBC,aAAgBA,ICQlB,SAASW,GAAUC,EAAKC,EAAMC,EAAOC,EAAMC,GAC1C,IAAIC,EACAvH,EACAtC,EACAiF,EACAhF,EACA6J,EACAC,EACA3I,EACA7D,EACAyM,EAKJ,GAHAJ,GAAS,EAIO,iBAARJ,GACC,OAARA,EAEA,OAAOA,EAER,GAAK3J,GAAU2J,GACd,OAAOJ,GAAYI,GAEpB,GAAKX,GAASW,GACb,OAnFF,SAAoBnF,GACnB,IAEI/B,EACA2C,EACAgF,EACAH,EACAxQ,EACAiE,EAPAmM,EAAQ,GACRC,EAAO,GA8BX,IArBArQ,EAAM,IAAI+K,EAAMzE,YAAayE,EAAM6F,SAEnCR,EAAM9E,KAAMP,GACZsF,EAAK/E,KAAMtL,GAGN+K,EAAM8F,QACV7Q,EAAI6Q,MAAQ9F,EAAM8F,OAGd9F,EAAM+F,OACV9Q,EAAI8Q,KAAO/F,EAAM+F,MAEb/F,EAAMgG,QACV/Q,EAAI+Q,MAAQhG,EAAMgG,OAEdhG,EAAMiG,UACVhR,EAAIgR,QAAUjG,EAAMiG,SAGrBhI,EAAOyG,GAAY1E,GACb9G,EAAI,EAAGA,EAAI+E,EAAK9E,OAAQD,IAC7BuM,EAAMxH,EAAM/E,GACZ0H,EAAOD,GAAoBX,EAAOyF,GAC7BxN,GAAY2I,EAAM,WACtBgF,EAAQ3K,GAAS+E,EAAOyF,IAAY,GAAK,GACzC7E,EAAKnK,MAAQyO,GAAUlF,EAAOyF,GAAOG,EAAKP,EAAOC,GAAO,IAEzDxQ,GAAgBG,EAAKwQ,EAAK7E,GAE3B,OAAO3L,EA0CCiR,CAAWf,GAKnB,GAAc,UAFdxJ,EAAOK,GAAQmJ,IAGd,OAAO,IAAIgB,MAAOhB,GAEnB,GAAc,WAATxJ,EACJ,OAAO8I,GAAQU,EAAI7P,YAEpB,GAAc,QAATqG,EACJ,OAAO,IAAIyK,IAAKjB,GAEjB,GAAc,QAATxJ,EACJ,OAAO,IAAI0K,IAAKlB,GAEjB,GACU,WAATxJ,GACS,YAATA,GACS,WAATA,EAGA,OAAOwJ,EAAI9M,UAGZ,GADAuD,EAAOqJ,GAAatJ,GAEnB,OAAOC,EAAMuJ,GAGd,GACU,UAATxJ,GACS,WAATA,EAGA,MAA8B,mBAAlB5G,OAAOuR,OA1KrB,SAAwBnB,GACvB,IAAIE,EACAkB,EACA5K,EACA2J,EACA1E,EACAgF,EACAF,EACAxM,EAUJ,IARAmM,EAAQ,GACRC,EAAO,GAEPI,EAAM3Q,OAAOyR,OAAQjJ,GAAgB4H,IACrCE,EAAM9E,KAAM4E,GACZG,EAAK/E,KAAMmF,GAEXa,EAAQ9F,GAAe0E,GACjBjM,EAAI,EAAGA,EAAIqN,EAAMpN,OAAQD,IAC9ByC,EAAO4K,EAAOrN,GACd0H,EAAOD,GAAoBwE,EAAKxJ,GAC3B1D,GAAY2I,EAAM,WACtBgF,EAAQ3K,GAASkK,EAAIxJ,IAAY,GAAK,GACtCiF,EAAKnK,MAAQyO,GAAUC,EAAIxJ,GAAOiK,EAAKP,EAAOC,GAAO,IAEtDxQ,GAAgB4Q,EAAK/J,EAAMiF,GAW5B,OATM7L,OAAO0R,aAActB,IAC1BpQ,OAAO2R,kBAAmBhB,GAEtB3Q,OAAO4R,SAAUxB,IACrBpQ,OAAO6R,KAAMlB,GAET3Q,OAAO8R,SAAU1B,IACrBpQ,OAAOuR,OAAQZ,GAETA,EAuIEoB,CAAe3B,GAEhB,GAIR,GADAlH,EAAOyG,GAAYS,GACdI,EAAQ,EAEZ,IADAC,EAAS7J,EACHgK,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAE7B5I,EAAIoI,EADJM,EAAMxH,EAAM0H,IAIZhK,EAAOK,GAAQe,GAED,iBAANA,GACD,OAANA,GAEU,UAATpB,GACS,WAATA,GAEDH,GAAUuB,GAEM,WAAXyI,GACJ5E,EAAOD,GAAoBwE,EAAKM,GAC3BxN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQyO,GAAUnI,IAExBjI,GAAgBsQ,EAAMK,EAAK7E,IAE3BwE,EAAMK,GAAQP,GAAUnI,IAMd,KADZ7D,EAAImG,GAASgG,EAAOtI,KAMpB2I,EAAQzK,GAAS8B,GAAQ,IAAI/B,MAAO+B,EAAE5D,QAAW,GACjDkM,EAAM9E,KAAMxD,GACZuI,EAAK/E,KAAMmF,GACK,UAAXF,EACJJ,EAAMK,GAAQP,GAAUnI,EAAG2I,EAAKL,EAAOC,EAAMC,IAE7C3E,EAAOD,GAAoBwE,EAAKM,GAC3BxN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQyO,GAAUnI,EAAG2I,EAAKL,EAAOC,EAAMC,IAE7CzQ,GAAgBsQ,EAAMK,EAAK7E,KAd3BwE,EAAMK,GAAQH,EAAMpM,QAiBhB,GAAc,UAATyC,EACX,IAAMgK,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAE7BP,EADAK,EAAMxH,EAAM0H,IACER,EAAKM,QAGpB,IAAME,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAC7BF,EAAMxH,EAAM0H,GACZ/E,EAAOD,GAAoBwE,EAAKM,GAChC3Q,GAAgBsQ,EAAMK,EAAK7E,GAY7B,OATM7L,OAAO0R,aAActB,IAC1BpQ,OAAO2R,kBAAmBtB,GAEtBrQ,OAAO4R,SAAUxB,IACrBpQ,OAAO6R,KAAMxB,GAETrQ,OAAO8R,SAAU1B,IACrBpQ,OAAOuR,OAAQlB,GAETA,EAMR,IC3RInK,GAAUjE,GACVqG,GAAuBxG,GAAmD6B,YAC1EsE,GAAOlG,GACPoO,GDwRaA,GCtOjB,IAAA6B,GAnBA,SAAetQ,EAAO8O,GACrB,IAAInN,EACJ,GAAKkC,UAAUnB,OAAS,EAAI,CAC3B,IAAMkE,GAAsBkI,GAC3B,MAAM,IAAIhP,UAAW,oEAAsEgP,EAAQ,MAEpG,GAAe,IAAVA,EACJ,OAAO9O,OAGR8O,EAAQvI,GAGT,OADA5E,EAAQ6C,GAASxE,GAAY,IAAIuE,MAAOvE,EAAM0C,QAAW,GAClD+L,GAAUzO,EAAO2B,EAAK,CAAC3B,GAAQ,CAAC2B,GAAMmN,ICd9CxO,GALWC,GC5BPiE,GAAUjE,GA8Bd,IC9BI2B,GDmBJ,SAAmBlC,GAClB,MACkB,iBAAVA,GACG,OAAVA,IACCwE,GAASxE,ICtBR4F,GAAaxF,GACb0G,GAAiBzG,GACjBmB,GAAaa,EACbP,GAAcwG,EAKdiI,GAAkBjS,OAAOK,UAgF7B,IAAA6B,GAvCA,SAAwBR,GACvB,IAAI+G,EAGJ,QAAM7E,GAAUlC,OAIhB+G,EAAQD,GAAgB9G,MAOtBwB,GAAYxB,EAAO,gBAGpBwB,GAAYuF,EAAO,gBACnBnB,GAAYmB,EAAMjC,cACmB,sBAArChD,GAAaiF,EAAMjC,cAGnBtD,GAAYuF,EAAO,kBACnBnB,GAAYmB,EAAMyJ,iBAIjBzJ,IAAUwJ,IAzDb,SAAmBhR,GAClB,IAAIyP,EAGJ,IAAMA,KAAOzP,EACZ,IAAMiC,GAAYjC,EAAKyP,GACtB,OAAO,EAGT,OAAO,EAmDLyB,CAAUzQ,MCjFTkC,GCegB3B,GDdhBiB,GAAapB,EACbgC,GAAW/B,EAAsC4B,YAqCrD,wJEvCIU,GAAUpC,GACVoO,GAAOvO,GACPsQ,GFeJ,SAAmBC,EAAMC,GACxB,OAAM1O,GAAU0O,GAGXpP,GAAYoP,EAAS,SACzBD,EAAKE,IAAMD,EAAQC,KACbzO,GAAUuO,EAAKE,MACb,IAAI/Q,UAAW,qEAAuE6Q,EAAKE,IAAM,MAGrGrP,GAAYoP,EAAS,aACzBD,EAAKvB,QAAUwB,EAAQxB,SACjBhN,GAAUuO,EAAKvB,UACb,IAAItP,UAAW,yEAA2E6Q,EAAKvB,QAAU,MAG3G,KAdC,IAAItP,UAAW,iEAAmE8Q,EAAU,OEhBjGE,GAAWzO,GAwDf,IAAA0O,GAnCA,SAAkBH,GACjB,IAAID,EACAnS,EAGJ,GAFAmS,EAAOhC,GAAMmC,IACbtS,EAAMkS,GAAUC,EAAMC,GAErB,MAAMpS,EAEP,OAUA,WACC,IAEIwS,EACAvO,EAHA6M,EAAOzL,UAAW,GAClBgN,EAAMF,EAAKE,IAAM,SAASvB,EAG9B,IAAM7M,EAAI,EAAGA,EAAIoB,UAAUnB,OAAQD,IAClCoO,GAAO,UAAYI,mBAAoBpN,UAAWpB,IAInD,OAFAuO,EAAMrO,GAASgO,EAAKvB,QAAS,UAAWyB,GACxCG,EAAMrO,GAASqO,EAAK,WAAY1B,KCtC9B4B,GCbU3Q,GACCH,IDWGG,EAOL2Q,GAAwB,UALvB7Q,IAUd,IAAAC,GAAiB4Q,UEiFjB,WACC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAnP,EACA0M,EACAzM,EASJ,IANA0O,EAAUtN,UAAW,GACrBuN,EAASvN,UAAW,GAGpBwN,GADAG,EAAQ3N,UAAW,GADnB0N,GAHAD,EAAQzN,UAAW,IAGLnB,UAECA,OACfgP,EAAMN,EACA3O,EAAI,EAAGA,EAAI8O,EAAO9O,IAAM,CAI7B,GAHAkP,EAAIL,EAAO7O,GACXyM,EAAIrL,UAAWpB,EAAE,GAEH,WADdgP,EAAOD,EAAO/O,EAAE4O,IAEVnC,EAAI,EACRA,EAAI,EACOA,GAAKyC,IAChBzC,EAAIyC,EAAI,QAEH,GAAc,SAATF,EACNvC,EAAI,GACRA,GAAKyC,GACI,GAEG,KADXzC,GAAKyC,KAEJzC,GAAKyC,GAGIzC,GAAKyC,IAChBzC,GAAKyC,IACKA,IACTzC,GAAKyC,QAGD,GAAKzC,EAAI,GAAKA,GAAKyC,EACzB,MAAM,IAAIC,WAAYC,GAAQ,+FAAgGpP,EAAGyM,KAElI1M,EAAI2O,EAAS1O,IAGJ,GAAgB,IAAX2O,EACbM,GAAOxC,EAAI1M,EAEXkP,GAAOxC,EAAI1M,EAGb,OAAOkP"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index be5ab40..50c5e03 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./browser.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..76dcdc8 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..acb12f3 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 6099b7db8d9af678f472a143cface1c4989b82e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:34:09 +0000 Subject: [PATCH 008/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index bc49a2b..be5ab40 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From 2bbb0022277bb9e3e02433f60f7a7d10896ff178 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:44:11 +0000 Subject: [PATCH 009/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 319dc4e..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).sub2ind=r()}(this,(function(){"use strict";function t(t){var r=t.default;if("function"==typeof r){var e=function(){return r.apply(this,arguments)};e.prototype=r.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(t).forEach((function(r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})})),e}var r="function"==typeof Object.defineProperty?Object.defineProperty:null;var e=function(){try{return r({},"x",{}),!0}catch(t){return!1}},n=Object.defineProperty,o=Object.prototype,i=o.toString,u=o.__defineGetter__,a=o.__defineSetter__,f=o.__lookupGetter__,c=o.__lookupSetter__;var s=function(t,r,e){var n,s,l,h;if("object"!=typeof t||null===t||"[object Array]"===i.call(t))throw new TypeError("invalid argument. First argument must be an object. Value: `"+t+"`.");if("object"!=typeof e||null===e||"[object Array]"===i.call(e))throw new TypeError("invalid argument. Property descriptor must be an object. Value: `"+e+"`.");if((s="value"in e)&&(f.call(t,r)||c.call(t,r)?(n=t.__proto__,t.__proto__=o,delete t[r],t[r]=e.value,t.__proto__=n):t[r]=e.value),l="get"in e,h="set"in e,s&&(l||h))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return l&&u&&u.call(t,r,e.get),h&&a&&a.call(t,r,e.set),t},l=n,h=s,p=e()?l:h,y=p;var v=function(t,r,e){y(t,r,{configurable:!1,enumerable:!1,writable:!1,value:e})},g=v;var w=function(t){return"string"==typeof t};var d=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var b=function(){return d&&"symbol"==typeof Symbol.toStringTag},m=Object.prototype.toString,A=m;var E=function(t){return A.call(t)},_=Object.prototype.hasOwnProperty;var O=function(t,r){return null!=t&&_.call(t,r)},P="function"==typeof Symbol?Symbol.toStringTag:"",j=O,R=P,T=m;var U=E,S=function(t){var r,e,n;if(null==t)return T.call(t);e=t[R],r=j(t,R);try{t[R]=void 0}catch(r){return T.call(t)}return n=T.call(t),r?t[R]=e:delete t[R],n},I=b()?S:U,B=String.prototype.valueOf;var Y=I,x=function(t){try{return B.call(t),!0}catch(t){return!1}},C=b();var M=function(t){return"object"==typeof t&&(t instanceof String||(C?x(t):"[object String]"===Y(t)))},L=w,F=M;var D=g,N=function(t){return L(t)||F(t)},k=M;D(N,"isPrimitive",w),D(N,"isObject",k);var V=N,z=V.isPrimitive,G=/[-\/\\^$*+?.()|[\]{}]/g;var X=function(t){var r,e;if(!z(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");if("/"===t[0])for(e=t.length-1;e>=0&&"/"!==t[e];e--);return void 0===e||e<=0?t.replace(G,"\\$&"):(r=(r=t.substring(1,e)).replace(G,"\\$&"),t=t[0]+r+t.substring(e))},$=/./;var H=function(t){return"boolean"==typeof t},W=Boolean.prototype.toString;var q=I,J=function(t){try{return W.call(t),!0}catch(t){return!1}},Z=b();var K=function(t){return"object"==typeof t&&(t instanceof Boolean||(Z?J(t):"[object Boolean]"===q(t)))},Q=H,tt=K;var rt=g,et=function(t){return Q(t)||tt(t)},nt=K;rt(et,"isPrimitive",H),rt(et,"isObject",nt);var ot=et;var it=function(){return new Function("return this;")()},ut="object"==typeof self?self:null,at="object"==typeof window?window:null,ft="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},ct="object"==typeof ft?ft:null;module.exports=ct;var st=ot.isPrimitive,lt=it,ht=ut,pt=at,yt=t(Object.freeze({__proto__:null}));var vt=function(t){if(arguments.length){if(!st(t))throw new TypeError("invalid argument. Must provide a boolean primitive. Value: `"+t+"`.");if(t)return lt()}if(ht)return ht;if(pt)return pt;if(yt)return yt;throw new Error("unexpected error. Unable to resolve global object.")},gt=vt(),wt=gt.document&>.document.childNodes,dt=Int8Array,bt=$,mt=wt,At=dt;var Et=function(){return"function"==typeof bt||"object"==typeof At||"function"==typeof mt};var _t=function(){return/^\s*function\s*([^(]*)/i},Ot=_t;g(Ot,"REGEXP",_t());var Pt=Ot,jt=I;var Rt=Array.isArray?Array.isArray:function(t){return"[object Array]"===jt(t)},Tt=Rt;var Ut=function(t){return null!==t&&"object"==typeof t};g(Ut,"isObjectLikeArray",function(t){if("function"!=typeof t)throw new TypeError("invalid argument. Must provide a function. Value: `"+t+"`.");return function(r){var e,n;if(!Tt(r))return!1;if(0===(e=r.length))return!1;for(n=0;ndr&&br(t)},Ar=hr.isPrimitive,Er=mr;var _r=function(t){return Ar(t)&&Er(t)},Or=hr.isObject,Pr=mr;var jr=function(t){return Or(t)&&Pr(t.valueOf())},Rr=_r,Tr=jr;var Ur=g,Sr=function(t){return Rr(t)||Tr(t)},Ir=jr;Ur(Sr,"isPrimitive",_r),Ur(Sr,"isObject",Ir);var Br=Sr,Yr=Br.isPrimitive;var xr=function(t){return Yr(t)&&t>=0},Cr=Br.isObject;var Mr=function(t){return Cr(t)&&t.valueOf()>=0},Lr=xr,Fr=Mr;var Dr=g,Nr=function(t){return Lr(t)||Fr(t)},kr=Mr;Dr(Nr,"isPrimitive",xr),Dr(Nr,"isObject",kr);var Vr=Nr,zr=Object.getPrototypeOf;var Gr=function(t){return t.__proto__},Xr=I,$r=Gr;var Hr=function(t){var r=$r(t);return r||null===r?r:"[object Function]"===Xr(t.constructor)?t.constructor.prototype:t instanceof Object?Object.prototype:null},Wr=zr,qr=Hr,Jr=zt(Object.getPrototypeOf)?Wr:qr;var Zr=function(t){return null==t?null:(t=Object(t),Jr(t))},Kr=Zr,Qr=I;var te=function(t){if("object"!=typeof t||null===t)return!1;if(t instanceof Error)return!0;for(;t;){if("[object Error]"===Qr(t))return!0;t=Kr(t)}return!1};var re=function(){return/^\/((?:\\\/|[^\/])+)\/([imgy]*)$/},ee=re;g(ee,"REGEXP",re());var ne=V.isPrimitive,oe=ee;var ie=function(t){if(!ne(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");return(t=oe().exec(t))?new RegExp(t[1],t[2]):null};var ue=function(t){return t!=t},ae=hr.isPrimitive,fe=ue;var ce=function(t){return ae(t)&&fe(t)},se=hr.isObject,le=ue;var he=function(t){return se(t)&&le(t.valueOf())},pe=ce,ye=he;var ve=g,ge=function(t){return pe(t)||ye(t)},we=he;ve(ge,"isPrimitive",ce),ve(ge,"isObject",we);var de=ge,be=gr;var me=de,Ae=function(t){return"object"==typeof t&&null!==t&&"number"==typeof t.length&&be(t.length)&&t.length>=0&&t.length<=9007199254740991},Ee=V.isPrimitive,_e=Br.isPrimitive;var Oe=function(t,r,e){var n,o;if(!Ae(t)&&!Ee(t))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+t+"`.");if(0===(n=t.length))return-1;if(3===arguments.length){if(!_e(e))throw new TypeError("invalid argument. `fromIndex` must be an integer. Value: `"+e+"`.");if(e>=0){if(e>=n)return-1;o=e}else(o=n+e)<0&&(o=0)}else o=0;if(me(r)){for(;o=0&&r=0&&t.length<=4294967295&&Ge(t,"callee")&&!Xe(t,"callee")},qe=We,Je=je,Ze=Array.prototype.slice;var Ke=function(t){return qe(t)?Je(Ze.call(t)):Je(t)};var Qe=ze((function(){}),"prototype"),tn=!ze({toString:null},"toString");var rn,en=function(t){return t.constructor&&t.constructor.prototype===t},nn="undefined"==typeof window?void 0:window,on=O,un=Pe,an=kt,fn=en,cn=["console","external","frame","frameElement","frames","innerHeight","innerWidth","outerHeight","outerWidth","pageXOffset","pageYOffset","parent","scrollLeft","scrollTop","scrollX","scrollY","self","webkitIndexedDB","webkitStorageInfo","window"],sn=nn;rn=function(){var t;if("undefined"===an(sn))return!1;for(t in sn)try{-1===un(cn,t)&&on(sn,t)&&null!==sn[t]&&"object"===an(sn[t])&&fn(sn[t])}catch(t){return!0}return!1}();var ln="undefined"!=typeof window,hn=rn,pn=en,yn=ln;var vn=St,gn=O,wn=We,dn=Qe,bn=tn,mn=function(t){if(!1===yn&&!hn)return pn(t);try{return pn(t)}catch(t){return!1}},An=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"];var En=je,_n=Ke,On=function(t){var r,e,n,o,i,u,a;if(o=[],wn(t)){for(a=0;a0&&!gn(t,"0"))for(a=0;a!1})),Cn=[],Mn=[],Ln="undefined"!=typeof Uint8Array?Uint8Array:Array,Fn=!1;function Dn(){Fn=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=0,e=t.length;r>18&63]+Cn[o>>12&63]+Cn[o>>6&63]+Cn[63&o]);return i.join("")}function kn(t){var r;Fn||Dn();for(var e=t.length,n=e%3,o="",i=[],u=16383,a=0,f=e-n;af?f:a+u));return 1===n?(r=t[e-1],o+=Cn[r>>2],o+=Cn[r<<4&63],o+="=="):2===n&&(r=(t[e-2]<<8)+t[e-1],o+=Cn[r>>10],o+=Cn[r>>4&63],o+=Cn[r<<2&63],o+="="),i.push(o),i.join("")}function Vn(t,r,e,n,o){var i,u,a=8*o-n-1,f=(1<>1,s=-7,l=e?o-1:0,h=e?-1:1,p=t[r+l];for(l+=h,i=p&(1<<-s)-1,p>>=-s,s+=a;s>0;i=256*i+t[r+l],l+=h,s-=8);for(u=i&(1<<-s)-1,i>>=-s,s+=n;s>0;u=256*u+t[r+l],l+=h,s-=8);if(0===i)i=1-c;else{if(i===f)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),i-=c}return(p?-1:1)*u*Math.pow(2,i-n)}function zn(t,r,e,n,o,i){var u,a,f,c=8*i-o-1,s=(1<>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,y=n?1:-1,v=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,u=s):(u=Math.floor(Math.log(r)/Math.LN2),r*(f=Math.pow(2,-u))<1&&(u--,f*=2),(r+=u+l>=1?h/f:h*Math.pow(2,1-l))*f>=2&&(u++,f/=2),u+l>=s?(a=0,u=s):u+l>=1?(a=(r*f-1)*Math.pow(2,o),u+=l):(a=r*Math.pow(2,l-1)*Math.pow(2,o),u=0));o>=8;t[e+p]=255&a,p+=y,a/=256,o-=8);for(u=u<0;t[e+p]=255&u,p+=y,u/=256,c-=8);t[e+p-y]|=128*v}var Gn={}.toString,Xn=Array.isArray||function(t){return"[object Array]"==Gn.call(t)};qn.TYPED_ARRAY_SUPPORT=void 0===ft.TYPED_ARRAY_SUPPORT||ft.TYPED_ARRAY_SUPPORT;var $n=Hn();function Hn(){return qn.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Wn(t,r){if(Hn()=Hn())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Hn().toString(16)+" bytes");return 0|t}function ro(t){return!(null==t||!t._isBuffer)}function eo(t,r){if(ro(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return So(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return Io(t).length;default:if(n)return So(t).length;r=(""+r).toLowerCase(),n=!0}}function no(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return bo(this,r,e);case"utf8":case"utf-8":return yo(this,r,e);case"ascii":return go(this,r,e);case"latin1":case"binary":return wo(this,r,e);case"base64":return po(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return mo(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function oo(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function io(t,r,e,n,o){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0){if(!o)return-1;e=0}if("string"==typeof r&&(r=qn.from(r,n)),ro(r))return 0===r.length?-1:uo(t,r,e,n,o);if("number"==typeof r)return r&=255,qn.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):uo(t,[r],e,n,o);throw new TypeError("val must be string, number or Buffer")}function uo(t,r,e,n,o){var i,u=1,a=t.length,f=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,a/=2,f/=2,e/=2}function c(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(o){var s=-1;for(i=e;ia&&(e=a-f),i=e;i>=0;i--){for(var l=!0,h=0;ho&&(n=o):n=o;var i=r.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var u=0;u>8,o=e%256,i.push(o),i.push(n);return i}(r,t.length-e),t,e,n)}function po(t,r,e){return 0===r&&e===t.length?kn(t):kn(t.slice(r,e))}function yo(t,r,e){e=Math.min(t.length,e);for(var n=[],o=r;o239?4:c>223?3:c>191?2:1;if(o+l<=e)switch(l){case 1:c<128&&(s=c);break;case 2:128==(192&(i=t[o+1]))&&(f=(31&c)<<6|63&i)>127&&(s=f);break;case 3:i=t[o+1],u=t[o+2],128==(192&i)&&128==(192&u)&&(f=(15&c)<<12|(63&i)<<6|63&u)>2047&&(f<55296||f>57343)&&(s=f);break;case 4:i=t[o+1],u=t[o+2],a=t[o+3],128==(192&i)&&128==(192&u)&&128==(192&a)&&(f=(15&c)<<18|(63&i)<<12|(63&u)<<6|63&a)>65535&&f<1114112&&(s=f)}null===s?(s=65533,l=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=l}return function(t){var r=t.length;if(r<=vo)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),""},qn.prototype.compare=function(t,r,e,n,o){if(!ro(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),r<0||e>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&r>=e)return 0;if(n>=o)return-1;if(r>=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),a=Math.min(i,u),f=this.slice(n,o),c=t.slice(r,e),s=0;so)&&(e=o),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return ao(this,t,r,e);case"utf8":case"utf-8":return fo(this,t,r,e);case"ascii":return co(this,t,r,e);case"latin1":case"binary":return so(this,t,r,e);case"base64":return lo(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ho(this,t,r,e);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},qn.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var vo=4096;function go(t,r,e){var n="";e=Math.min(t.length,e);for(var o=r;on)&&(e=n);for(var o="",i=r;ie)throw new RangeError("Trying to access beyond buffer length")}function Eo(t,r,e,n,o,i){if(!ro(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>o||rt.length)throw new RangeError("Index out of range")}function _o(t,r,e,n){r<0&&(r=65535+r+1);for(var o=0,i=Math.min(t.length-e,2);o>>8*(n?o:1-o)}function Oo(t,r,e,n){r<0&&(r=4294967295+r+1);for(var o=0,i=Math.min(t.length-e,4);o>>8*(n?o:3-o)&255}function Po(t,r,e,n,o,i){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function jo(t,r,e,n,o){return o||Po(t,0,e,4),zn(t,r,e,n,23,4),e+4}function Ro(t,r,e,n,o){return o||Po(t,0,e,8),zn(t,r,e,n,52,8),e+8}qn.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(o*=256);)n+=this[t+--r]*o;return n},qn.prototype.readUInt8=function(t,r){return r||Ao(t,1,this.length),this[t]},qn.prototype.readUInt16LE=function(t,r){return r||Ao(t,2,this.length),this[t]|this[t+1]<<8},qn.prototype.readUInt16BE=function(t,r){return r||Ao(t,2,this.length),this[t]<<8|this[t+1]},qn.prototype.readUInt32LE=function(t,r){return r||Ao(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},qn.prototype.readUInt32BE=function(t,r){return r||Ao(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},qn.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||Ao(t,r,this.length);for(var n=this[t],o=1,i=0;++i=(o*=128)&&(n-=Math.pow(2,8*r)),n},qn.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||Ao(t,r,this.length);for(var n=r,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*r)),i},qn.prototype.readInt8=function(t,r){return r||Ao(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},qn.prototype.readInt16LE=function(t,r){r||Ao(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},qn.prototype.readInt16BE=function(t,r){r||Ao(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},qn.prototype.readInt32LE=function(t,r){return r||Ao(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},qn.prototype.readInt32BE=function(t,r){return r||Ao(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},qn.prototype.readFloatLE=function(t,r){return r||Ao(t,4,this.length),Vn(this,t,!0,23,4)},qn.prototype.readFloatBE=function(t,r){return r||Ao(t,4,this.length),Vn(this,t,!1,23,4)},qn.prototype.readDoubleLE=function(t,r){return r||Ao(t,8,this.length),Vn(this,t,!0,52,8)},qn.prototype.readDoubleBE=function(t,r){return r||Ao(t,8,this.length),Vn(this,t,!1,52,8)},qn.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||Eo(this,t,r,e,Math.pow(2,8*e)-1,0);var o=1,i=0;for(this[r]=255&t;++i=0&&(i*=256);)this[r+o]=t/i&255;return r+e},qn.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,1,255,0),qn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},qn.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,65535,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):_o(this,t,r,!0),r+2},qn.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,65535,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):_o(this,t,r,!1),r+2},qn.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,4294967295,0),qn.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):Oo(this,t,r,!0),r+4},qn.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,4294967295,0),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Oo(this,t,r,!1),r+4},qn.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Eo(this,t,r,e,o-1,-o)}var i=0,u=1,a=0;for(this[r]=255&t;++i>0)-a&255;return r+e},qn.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Eo(this,t,r,e,o-1,-o)}var i=e-1,u=1,a=0;for(this[r+i]=255&t;--i>=0&&(u*=256);)t<0&&0===a&&0!==this[r+i+1]&&(a=1),this[r+i]=(t/u>>0)-a&255;return r+e},qn.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,1,127,-128),qn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},qn.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,32767,-32768),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):_o(this,t,r,!0),r+2},qn.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,2,32767,-32768),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):_o(this,t,r,!1),r+2},qn.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,2147483647,-2147483648),qn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):Oo(this,t,r,!0),r+4},qn.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||Eo(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),qn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Oo(this,t,r,!1),r+4},qn.prototype.writeFloatLE=function(t,r,e){return jo(this,t,r,!0,e)},qn.prototype.writeFloatBE=function(t,r,e){return jo(this,t,r,!1,e)},qn.prototype.writeDoubleLE=function(t,r,e){return Ro(this,t,r,!0,e)},qn.prototype.writeDoubleBE=function(t,r,e){return Ro(this,t,r,!1,e)},qn.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--o)t[o+r]=this[o+e];else if(i<1e3||!qn.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(i=r;i55295&&e<57344){if(!o){if(e>56319){(r-=3)>-1&&i.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&i.push(239,191,189);continue}o=e;continue}if(e<56320){(r-=3)>-1&&i.push(239,191,189),o=e;continue}e=65536+(o-55296<<10|e-56320)}else o&&(r-=3)>-1&&i.push(239,191,189);if(o=null,e<128){if((r-=1)<0)break;i.push(e)}else if(e<2048){if((r-=2)<0)break;i.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;i.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;i.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return i}function Io(t){return function(t){var r,e,n,o,i,u;Fn||Dn();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[a-2]?2:"="===t[a-1]?1:0,u=new Ln(3*a/4-i),n=i>0?a-4:a;var f=0;for(r=0,e=0;r>16&255,u[f++]=o>>8&255,u[f++]=255&o;return 2===i?(o=Mn[t.charCodeAt(r)]<<2|Mn[t.charCodeAt(r+1)]>>4,u[f++]=255&o):1===i&&(o=Mn[t.charCodeAt(r)]<<10|Mn[t.charCodeAt(r+1)]<<4|Mn[t.charCodeAt(r+2)]>>2,u[f++]=o>>8&255,u[f++]=255&o),u}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(To,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Bo(t,r,e,n){for(var o=0;o=r.length||o>=t.length);++o)r[o+e]=t[o];return o}function Yo(t){return null!=t&&(!!t._isBuffer||xo(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&xo(t.slice(0,0))}(t))}function xo(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var Co=t(Object.freeze({__proto__:null,Buffer:qn,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),qn.alloc(+t)},isBuffer:Yo,kMaxLength:$n})).Buffer,Mo=function(){throw new Error("not implemented")},Lo=xn()?Co:Mo,Fo=zt(Lo.from),Do=Bt,No=Lo;var ko=function(t){if(!Do(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return No.from(t)},Vo=Bt,zo=Lo;var Go=function(t){if(!Vo(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return new zo(t)},Xo=Fo?ko:Go,$o=I,Ho="function"==typeof Int8Array;var Wo="function"==typeof Int8Array?Int8Array:null,qo=function(t){return Ho&&t instanceof Int8Array||"[object Int8Array]"===$o(t)},Jo=Wo;var Zo=function(){var t,r;if("function"!=typeof Jo)return!1;try{r=new Jo([1,3.14,-3.14,128]),t=qo(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-128===r[3]}catch(r){t=!1}return t};var Ko="function"==typeof Int8Array?Int8Array:void 0,Qo=function(){throw new Error("not implemented")},ti=Zo()?Ko:Qo,ri=I,ei="function"==typeof Uint8Array;var ni="function"==typeof Uint8Array?Uint8Array:null,oi=function(t){return ei&&t instanceof Uint8Array||"[object Uint8Array]"===ri(t)},ii=ni;var ui=function(){var t,r;if("function"!=typeof ii)return!1;try{r=new ii(r=[1,3.14,-3.14,256,257]),t=oi(r)&&1===r[0]&&3===r[1]&&253===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var ai="function"==typeof Uint8Array?Uint8Array:void 0,fi=function(){throw new Error("not implemented")},ci=ui()?ai:fi,si=I,li="function"==typeof Uint8ClampedArray;var hi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:null,pi=function(t){return li&&t instanceof Uint8ClampedArray||"[object Uint8ClampedArray]"===si(t)},yi=hi;var vi=function(){var t,r;if("function"!=typeof yi)return!1;try{r=new yi([-1,0,1,3.14,4.99,255,256]),t=pi(r)&&0===r[0]&&0===r[1]&&1===r[2]&&3===r[3]&&5===r[4]&&255===r[5]&&255===r[6]}catch(r){t=!1}return t};var gi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:void 0,wi=function(){throw new Error("not implemented")},di=vi()?gi:wi,bi=I,mi="function"==typeof Int16Array;var Ai="function"==typeof Int16Array?Int16Array:null,Ei=function(t){return mi&&t instanceof Int16Array||"[object Int16Array]"===bi(t)},_i=Ai;var Oi=function(){var t,r;if("function"!=typeof _i)return!1;try{r=new _i([1,3.14,-3.14,32768]),t=Ei(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-32768===r[3]}catch(r){t=!1}return t};var Pi="function"==typeof Int16Array?Int16Array:void 0,ji=function(){throw new Error("not implemented")},Ri=Oi()?Pi:ji,Ti=I,Ui="function"==typeof Uint16Array;var Si="function"==typeof Uint16Array?Uint16Array:null,Ii=function(t){return Ui&&t instanceof Uint16Array||"[object Uint16Array]"===Ti(t)},Bi=Si;var Yi=function(){var t,r;if("function"!=typeof Bi)return!1;try{r=new Bi(r=[1,3.14,-3.14,65536,65537]),t=Ii(r)&&1===r[0]&&3===r[1]&&65533===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var xi="function"==typeof Uint16Array?Uint16Array:void 0,Ci=function(){throw new Error("not implemented")},Mi=Yi()?xi:Ci,Li=I,Fi="function"==typeof Int32Array;var Di="function"==typeof Int32Array?Int32Array:null,Ni=function(t){return Fi&&t instanceof Int32Array||"[object Int32Array]"===Li(t)},ki=Di;var Vi=function(){var t,r;if("function"!=typeof ki)return!1;try{r=new ki([1,3.14,-3.14,2147483648]),t=Ni(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-2147483648===r[3]}catch(r){t=!1}return t};var zi="function"==typeof Int32Array?Int32Array:void 0,Gi=function(){throw new Error("not implemented")},Xi=Vi()?zi:Gi,$i=I,Hi="function"==typeof Uint32Array;var Wi="function"==typeof Uint32Array?Uint32Array:null,qi=function(t){return Hi&&t instanceof Uint32Array||"[object Uint32Array]"===$i(t)},Ji=Wi;var Zi=function(){var t,r;if("function"!=typeof Ji)return!1;try{r=new Ji(r=[1,3.14,-3.14,4294967296,4294967297]),t=qi(r)&&1===r[0]&&3===r[1]&&4294967293===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var Ki="function"==typeof Uint32Array?Uint32Array:void 0,Qi=function(){throw new Error("not implemented")},tu=Zi()?Ki:Qi,ru=I,eu="function"==typeof Float32Array;var nu="function"==typeof Float32Array?Float32Array:null,ou=function(t){return eu&&t instanceof Float32Array||"[object Float32Array]"===ru(t)},iu=pr,uu=nu;var au=function(){var t,r;if("function"!=typeof uu)return!1;try{r=new uu([1,3.14,-3.14,5e40]),t=ou(r)&&1===r[0]&&3.140000104904175===r[1]&&-3.140000104904175===r[2]&&r[3]===iu}catch(r){t=!1}return t};var fu="function"==typeof Float32Array?Float32Array:void 0,cu=function(){throw new Error("not implemented")},su=au()?fu:cu,lu=I,hu="function"==typeof Float64Array;var pu="function"==typeof Float64Array?Float64Array:null,yu=function(t){return hu&&t instanceof Float64Array||"[object Float64Array]"===lu(t)},vu=pu;var gu=function(){var t,r;if("function"!=typeof vu)return!1;try{r=new vu([1,3.14,-3.14,NaN]),t=yu(r)&&1===r[0]&&3.14===r[1]&&-3.14===r[2]&&r[3]!=r[3]}catch(r){t=!1}return t};var wu,du="function"==typeof Float64Array?Float64Array:void 0,bu=function(){throw new Error("not implemented")};wu=gu()?du:bu;var mu=ti,Au=ci,Eu=di,_u=Ri,Ou=Mi,Pu=Xi,ju=tu,Ru=su,Tu=wu;function Uu(t){return new mu(t)}function Su(t){return new Au(t)}function Iu(t){return new Eu(t)}function Bu(t){return new _u(t)}function Yu(t){return new Ou(t)}function xu(t){return new Pu(t)}function Cu(t){return new ju(t)}function Mu(t){return new Ru(t)}function Lu(t){return new Tu(t)}var Fu=O,Du=Rt,Nu=Bt,ku=te,Vu=kt,zu=ie,Gu=Pe,Xu=Pn,$u=Un,Hu=Yn,Wu=Zr,qu=p,Ju=Xo,Zu={int8array:Uu,uint8array:Su,uint8clampedarray:Iu,int16array:Bu,uint16array:Yu,int32array:xu,uint32array:Cu,float32array:Mu,float64array:Lu};function Ku(t,r,e,n,o){var i,u,a,f,c,s,l,h,p,y;if(o-=1,"object"!=typeof t||null===t)return t;if(Nu(t))return Ju(t);if(ku(t))return function(t){var r,e,n,o,i,u,a=[],f=[];for(i=new t.constructor(t.message),a.push(t),f.push(i),t.stack&&(i.stack=t.stack),t.code&&(i.code=t.code),t.errno&&(i.errno=t.errno),t.syscall&&(i.syscall=t.syscall),r=Xu(t),u=0;u0)for(i=a,y=0;y1){if(!ta(r))throw new TypeError("invalid argument. `level` must be a nonnegative integer. Value: `"+r+"`.");if(0===r)return t}else r=ra;return e=Qu(t)?new Array(t.length):{},ea(t,e,[t],[e],r)},oa=na,ia=Rt;var ua=function(t){return"object"==typeof t&&null!==t&&!ia(t)},aa=zt,fa=Zr,ca=O,sa=I,la=Object.prototype;var ha=function(t){var r;return!!ua(t)&&(!(r=fa(t))||!ca(t,"constructor")&&ca(r,"constructor")&&aa(r.constructor)&&"[object Function]"===sa(r.constructor)&&ca(r,"isPrototypeOf")&&aa(r.isPrototypeOf)&&(r===la||function(t){var r;for(r in t)if(!ca(t,r))return!1;return!0}(t)))},pa=ha,ya=O,va=V.isPrimitive;var ga={url:"https://stdlib.io/docs/api/latest/error-decoder.html",message:"Minified stdlib error code: {{code}}. Visit {{url}} for the full message."},wa=Kt,da=oa,ba=function(t,r){return pa(r)?ya(r,"url")&&(t.url=r.url,!va(t.url))?new TypeError("invalid option. `url` option must be a string primitive. Option: `"+t.url+"`."):ya(r,"message")&&(t.message=r.message,!va(t.message))?new TypeError("invalid option. `message` option must be a string primitive. Option: `"+t.message+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.")},ma=ga;var Aa=function(t){var r,e;if(r=da(ma),e=ba(r,t))throw e;return function(){var t,e,n=arguments[0],o=r.url+"?code="+n;for(e=1;e=f&&(s=f-1);else if("wrap"===u)s<0?(s+=f)<0&&0!==(s%=f)&&(s+=f):s>=f&&(s-=f)>=f&&(s%=f);else if(s<0||s>=f)throw new RangeError(_a("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",l,s));(c=t[l])<0&&0===r?a-=s*c:a+=s*c}return a}})); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 75b90f6..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/utils-define-property/lib/define_property.js","../node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js","../node_modules/@stdlib/utils-define-property/lib/builtin.js","../node_modules/@stdlib/utils-define-property/lib/polyfill.js","../node_modules/@stdlib/utils-define-property/lib/index.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/primitive.js","../node_modules/@stdlib/assert-has-symbol-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostring.js","../node_modules/@stdlib/utils-native-class/lib/native_class.js","../node_modules/@stdlib/assert-has-own-property/lib/main.js","../node_modules/@stdlib/assert-has-own-property/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostringtag.js","../node_modules/@stdlib/utils-native-class/lib/polyfill.js","../node_modules/@stdlib/utils-native-class/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/try2valueof.js","../node_modules/@stdlib/assert-is-string/lib/valueof.js","../node_modules/@stdlib/assert-is-string/lib/object.js","../node_modules/@stdlib/assert-is-string/lib/main.js","../node_modules/@stdlib/assert-is-string/lib/index.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/main.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/re.js","../node_modules/@stdlib/assert-is-boolean/lib/primitive.js","../node_modules/@stdlib/assert-is-boolean/lib/try2serialize.js","../node_modules/@stdlib/assert-is-boolean/lib/tostring.js","../node_modules/@stdlib/assert-is-boolean/lib/object.js","../node_modules/@stdlib/assert-is-boolean/lib/main.js","../node_modules/@stdlib/assert-is-boolean/lib/index.js","../node_modules/@stdlib/utils-global/lib/codegen.js","../node_modules/@stdlib/utils-global/lib/self.js","../node_modules/@stdlib/utils-global/lib/window.js","../node_modules/@stdlib/utils-global/lib/global.js","../node_modules/@stdlib/utils-global/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/nodelist.js","../node_modules/@stdlib/utils-global/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/typedarray.js","../node_modules/@stdlib/utils-type-of/lib/check.js","../node_modules/@stdlib/regexp-function-name/lib/main.js","../node_modules/@stdlib/regexp-function-name/lib/index.js","../node_modules/@stdlib/regexp-function-name/lib/regexp.js","../node_modules/@stdlib/assert-is-array/lib/main.js","../node_modules/@stdlib/assert-is-array/lib/index.js","../node_modules/@stdlib/assert-tools-array-function/lib/arrayfcn.js","../node_modules/@stdlib/assert-is-object-like/lib/main.js","../node_modules/@stdlib/assert-is-object-like/lib/index.js","../node_modules/@stdlib/assert-is-buffer/lib/main.js","../node_modules/@stdlib/assert-is-buffer/lib/index.js","../node_modules/@stdlib/utils-constructor-name/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/typeof.js","../node_modules/@stdlib/utils-constructor-name/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/polyfill.js","../node_modules/@stdlib/utils-type-of/lib/index.js","../node_modules/@stdlib/assert-is-function/lib/main.js","../node_modules/@stdlib/assert-is-function/lib/index.js","../node_modules/@stdlib/assert-is-regexp/lib/try2exec.js","../node_modules/@stdlib/assert-is-regexp/lib/exec.js","../node_modules/@stdlib/assert-is-regexp/lib/main.js","../node_modules/@stdlib/string-replace/lib/replace.js","../node_modules/@stdlib/string-replace/lib/index.js","../node_modules/@stdlib/assert-is-number/lib/primitive.js","../node_modules/@stdlib/number-ctor/lib/index.js","../node_modules/@stdlib/number-ctor/lib/number.js","../node_modules/@stdlib/assert-is-number/lib/try2serialize.js","../node_modules/@stdlib/assert-is-number/lib/tostring.js","../node_modules/@stdlib/assert-is-number/lib/object.js","../node_modules/@stdlib/assert-is-number/lib/main.js","../node_modules/@stdlib/assert-is-number/lib/index.js","../node_modules/@stdlib/constants-float64-pinf/lib/index.js","../node_modules/@stdlib/constants-float64-ninf/lib/index.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/is_integer.js","../node_modules/@stdlib/math-base-special-floor/lib/main.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-integer/lib/integer.js","../node_modules/@stdlib/assert-is-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-integer/lib/object.js","../node_modules/@stdlib/assert-is-integer/lib/main.js","../node_modules/@stdlib/assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/object.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/main.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/index.js","../node_modules/@stdlib/utils-get-prototype-of/lib/native.js","../node_modules/@stdlib/utils-get-prototype-of/lib/proto.js","../node_modules/@stdlib/utils-get-prototype-of/lib/polyfill.js","../node_modules/@stdlib/utils-get-prototype-of/lib/detect.js","../node_modules/@stdlib/utils-get-prototype-of/lib/get_prototype_of.js","../node_modules/@stdlib/utils-get-prototype-of/lib/index.js","../node_modules/@stdlib/assert-is-error/lib/main.js","../node_modules/@stdlib/assert-is-error/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/main.js","../node_modules/@stdlib/regexp-regexp/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/regexp.js","../node_modules/@stdlib/utils-regexp-from-string/lib/from_string.js","../node_modules/@stdlib/utils-regexp-from-string/lib/index.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/primitive.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-nan/lib/object.js","../node_modules/@stdlib/assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-collection/lib/main.js","../node_modules/@stdlib/utils-index-of/lib/index_of.js","../node_modules/@stdlib/constants-array-max-typed-array-length/lib/index.js","../node_modules/@stdlib/utils-index-of/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin.js","../node_modules/@stdlib/utils-keys/lib/has_arguments_bug.js","../node_modules/@stdlib/utils-keys/lib/has_builtin.js","../node_modules/@stdlib/assert-is-arguments/lib/main.js","../node_modules/@stdlib/assert-is-arguments/lib/detect.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/has_string_enumerability_bug.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/native.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/main.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/index.js","../node_modules/@stdlib/assert-is-arguments/lib/polyfill.js","../node_modules/@stdlib/assert-is-arguments/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin_wrapper.js","../node_modules/@stdlib/utils-noop/lib/noop.js","../node_modules/@stdlib/utils-keys/lib/has_enumerable_prototype_bug.js","../node_modules/@stdlib/utils-keys/lib/has_non_enumerable_properties_bug.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype.js","../node_modules/@stdlib/utils-keys/lib/has_automation_equality_bug.js","../node_modules/@stdlib/utils-keys/lib/window.js","../node_modules/@stdlib/utils-keys/lib/has_window.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype_wrapper.js","../node_modules/@stdlib/utils-keys/lib/polyfill.js","../node_modules/@stdlib/utils-keys/lib/main.js","../node_modules/@stdlib/utils-keys/lib/index.js","../node_modules/@stdlib/utils-property-names/lib/has_builtin.js","../node_modules/@stdlib/utils-property-names/lib/builtin.js","../node_modules/@stdlib/utils-property-names/lib/polyfill.js","../node_modules/@stdlib/utils-property-names/lib/index.js","../node_modules/@stdlib/utils-property-descriptor/lib/has_builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/polyfill.js","../node_modules/@stdlib/utils-property-descriptor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/polyfill.js","../node_modules/@stdlib/buffer-ctor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/buffer.js","../node_modules/@stdlib/buffer-from-buffer/lib/has_from.js","../node_modules/@stdlib/buffer-from-buffer/lib/main.js","../node_modules/@stdlib/buffer-from-buffer/lib/polyfill.js","../node_modules/@stdlib/buffer-from-buffer/lib/index.js","../node_modules/@stdlib/assert-is-int8array/lib/main.js","../node_modules/@stdlib/assert-has-int8array-support/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/main.js","../node_modules/@stdlib/constants-int8-min/lib/index.js","../node_modules/@stdlib/array-int8/lib/polyfill.js","../node_modules/@stdlib/array-int8/lib/index.js","../node_modules/@stdlib/array-int8/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8array/lib/main.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/main.js","../node_modules/@stdlib/array-uint8/lib/polyfill.js","../node_modules/@stdlib/array-uint8/lib/index.js","../node_modules/@stdlib/array-uint8/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8clampedarray/lib/main.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/main.js","../node_modules/@stdlib/array-uint8c/lib/polyfill.js","../node_modules/@stdlib/array-uint8c/lib/index.js","../node_modules/@stdlib/array-uint8c/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/index.js","../node_modules/@stdlib/assert-is-int16array/lib/main.js","../node_modules/@stdlib/assert-has-int16array-support/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/main.js","../node_modules/@stdlib/constants-int16-min/lib/index.js","../node_modules/@stdlib/array-int16/lib/polyfill.js","../node_modules/@stdlib/array-int16/lib/index.js","../node_modules/@stdlib/array-int16/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint16array/lib/main.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/main.js","../node_modules/@stdlib/array-uint16/lib/polyfill.js","../node_modules/@stdlib/array-uint16/lib/index.js","../node_modules/@stdlib/array-uint16/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/index.js","../node_modules/@stdlib/assert-is-int32array/lib/main.js","../node_modules/@stdlib/assert-has-int32array-support/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/main.js","../node_modules/@stdlib/constants-int32-min/lib/index.js","../node_modules/@stdlib/array-int32/lib/polyfill.js","../node_modules/@stdlib/array-int32/lib/index.js","../node_modules/@stdlib/array-int32/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint32array/lib/main.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/main.js","../node_modules/@stdlib/array-uint32/lib/polyfill.js","../node_modules/@stdlib/array-uint32/lib/index.js","../node_modules/@stdlib/array-uint32/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float32array/lib/main.js","../node_modules/@stdlib/assert-has-float32array-support/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/main.js","../node_modules/@stdlib/array-float32/lib/polyfill.js","../node_modules/@stdlib/array-float32/lib/index.js","../node_modules/@stdlib/array-float32/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float64array/lib/main.js","../node_modules/@stdlib/assert-has-float64array-support/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/main.js","../node_modules/@stdlib/array-float64/lib/polyfill.js","../node_modules/@stdlib/array-float64/lib/index.js","../node_modules/@stdlib/array-float64/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/index.js","../node_modules/@stdlib/utils-copy/lib/typed_arrays.js","../node_modules/@stdlib/utils-copy/lib/deep_copy.js","../node_modules/@stdlib/utils-copy/lib/copy.js","../node_modules/@stdlib/utils-copy/lib/index.js","../node_modules/@stdlib/assert-is-object/lib/main.js","../node_modules/@stdlib/assert-is-plain-object/lib/main.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/validate.js","../node_modules/@stdlib/assert-is-plain-object/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/factory.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\nvar main = ( typeof Object.defineProperty === 'function' ) ? Object.defineProperty : null;\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar defineProperty = require( './define_property.js' );\n\n\n// MAIN //\n\n/**\n* Tests for `Object.defineProperty` support.\n*\n* @private\n* @returns {boolean} boolean indicating if an environment has `Object.defineProperty` support\n*\n* @example\n* var bool = hasDefinePropertySupport();\n* // returns \n*/\nfunction hasDefinePropertySupport() {\n\t// Test basic support...\n\ttry {\n\t\tdefineProperty( {}, 'x', {} );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasDefinePropertySupport;\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// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @name defineProperty\n* @type {Function}\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nvar defineProperty = Object.defineProperty;\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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/* eslint-disable no-underscore-dangle, no-proto */\n\n'use strict';\n\n// VARIABLES //\n\nvar objectProtoype = Object.prototype;\nvar toStr = objectProtoype.toString;\nvar defineGetter = objectProtoype.__defineGetter__;\nvar defineSetter = objectProtoype.__defineSetter__;\nvar lookupGetter = objectProtoype.__lookupGetter__;\nvar lookupSetter = objectProtoype.__lookupSetter__;\n\n\n// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @param {Object} obj - object on which to define the property\n* @param {string} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nfunction defineProperty( obj, prop, descriptor ) {\n\tvar prototype;\n\tvar hasValue;\n\tvar hasGet;\n\tvar hasSet;\n\n\tif ( typeof obj !== 'object' || obj === null || toStr.call( obj ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an object. Value: `' + obj + '`.' );\n\t}\n\tif ( typeof descriptor !== 'object' || descriptor === null || toStr.call( descriptor ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. Property descriptor must be an object. Value: `' + descriptor + '`.' );\n\t}\n\thasValue = ( 'value' in descriptor );\n\tif ( hasValue ) {\n\t\tif (\n\t\t\tlookupGetter.call( obj, prop ) ||\n\t\t\tlookupSetter.call( obj, prop )\n\t\t) {\n\t\t\t// Override `__proto__` to avoid touching inherited accessors:\n\t\t\tprototype = obj.__proto__;\n\t\t\tobj.__proto__ = objectProtoype;\n\n\t\t\t// Delete property as existing getters/setters prevent assigning value to specified property:\n\t\t\tdelete obj[ prop ];\n\t\t\tobj[ prop ] = descriptor.value;\n\n\t\t\t// Restore original prototype:\n\t\t\tobj.__proto__ = prototype;\n\t\t} else {\n\t\t\tobj[ prop ] = descriptor.value;\n\t\t}\n\t}\n\thasGet = ( 'get' in descriptor );\n\thasSet = ( 'set' in descriptor );\n\n\tif ( hasValue && ( hasGet || hasSet ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.' );\n\t}\n\n\tif ( hasGet && defineGetter ) {\n\t\tdefineGetter.call( obj, prop, descriptor.get );\n\t}\n\tif ( hasSet && defineSetter ) {\n\t\tdefineSetter.call( obj, prop, descriptor.set );\n\t}\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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* Define (or modify) an object property.\n*\n* @module @stdlib/utils-define-property\n*\n* @example\n* var defineProperty = require( '@stdlib/utils-define-property' );\n*\n* var obj = {};\n* defineProperty( obj, 'foo', {\n* 'value': 'bar',\n* 'writable': false,\n* 'configurable': false,\n* 'enumerable': false\n* });\n* obj.foo = 'boop'; // => throws\n*/\n\n// MODULES //\n\nvar hasDefinePropertySupport = require( './has_define_property_support.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar defineProperty;\nif ( hasDefinePropertySupport() ) {\n\tdefineProperty = builtin;\n} else {\n\tdefineProperty = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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\nvar defineProperty = require( '@stdlib/utils-define-property' );\n\n\n// MAIN //\n\n/**\n* Defines a non-enumerable read-only property.\n*\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setNonEnumerableReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Define a non-enumerable read-only property.\n*\n* @module @stdlib/utils-define-nonenumerable-read-only-property\n*\n* @example\n* var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\n*\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\n\n// MODULES //\n\nvar setNonEnumerableReadOnly = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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// MAIN //\n\n/**\n* Tests for native `Symbol` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Symbol` support\n*\n* @example\n* var bool = hasSymbolSupport();\n* // returns \n*/\nfunction hasSymbolSupport() {\n\treturn (\n\t\ttypeof Symbol === 'function' &&\n\t\ttypeof Symbol( 'foo' ) === 'symbol'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasSymbolSupport;\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\nvar hasSymbols = require( '@stdlib/assert-has-symbol-support' );\n\n\n// VARIABLES //\n\nvar FLG = hasSymbols();\n\n\n// MAIN //\n\n/**\n* Tests for native `toStringTag` support.\n*\n* @returns {boolean} boolean indicating if an environment has `toStringTag` support\n*\n* @example\n* var bool = hasToStringTagSupport();\n* // returns \n*/\nfunction hasToStringTagSupport() {\n\treturn ( FLG && typeof Symbol.toStringTag === 'symbol' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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* Test for native `toStringTag` support.\n*\n* @module @stdlib/assert-has-tostringtag-support\n*\n* @example\n* var hasToStringTagSupport = require( '@stdlib/assert-has-tostringtag-support' );\n*\n* var bool = hasToStringTagSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasToStringTagSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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// MAIN //\n\nvar toStr = Object.prototype.toString;\n\n\n// EXPORTS //\n\nmodule.exports = toStr;\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\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification (via the internal property `[[Class]]`) of an object.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\treturn toStr.call( v );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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// FUNCTIONS //\n\nvar has = Object.prototype.hasOwnProperty;\n\n\n// MAIN //\n\n/**\n* Tests if an object has a specified property.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object has a specified property\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'bap' );\n* // returns false\n*/\nfunction hasOwnProp( value, property ) {\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\treturn has.call( value, property );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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* Test whether an object has a specified property.\n*\n* @module @stdlib/assert-has-own-property\n*\n* @example\n* var hasOwnProp = require( '@stdlib/assert-has-own-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* bool = hasOwnProp( beep, 'bop' );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasOwnProp = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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// MAIN //\n\nvar toStrTag = ( typeof Symbol === 'function' ) ? Symbol.toStringTag : '';\n\n\n// EXPORTS //\n\nmodule.exports = toStrTag;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar toStringTag = require( './tostringtag.js' );\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification of an object in environments supporting `Symbol.toStringTag`.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\tvar isOwn;\n\tvar tag;\n\tvar out;\n\n\tif ( v === null || v === void 0 ) {\n\t\treturn toStr.call( v );\n\t}\n\ttag = v[ toStringTag ];\n\tisOwn = hasOwnProp( v, toStringTag );\n\n\t// Attempt to override the `toStringTag` property. For built-ins having a `Symbol.toStringTag` property (e.g., `JSON`, `Math`, etc), the `Symbol.toStringTag` property is read-only (e.g., , so we need to wrap in a `try/catch`.\n\ttry {\n\t\tv[ toStringTag ] = void 0;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn toStr.call( v );\n\t}\n\tout = toStr.call( v );\n\n\tif ( isOwn ) {\n\t\tv[ toStringTag ] = tag;\n\t} else {\n\t\tdelete v[ toStringTag ];\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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* Return a string value indicating a specification defined classification of an object.\n*\n* @module @stdlib/utils-native-class\n*\n* @example\n* var nativeClass = require( '@stdlib/utils-native-class' );\n*\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* function Beep() {\n* return this;\n* }\n* str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\n\n// MODULES //\n\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar builtin = require( './native_class.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar nativeClass;\nif ( hasToStringTag() ) {\n\tnativeClass = polyfill;\n} else {\n\tnativeClass = builtin;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to extract a string value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a string can be extracted\n*/\nfunction test( value ) {\n\ttry {\n\t\tvalueOf.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar valueOf = String.prototype.valueOf; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2valueof.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string object\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns false\n*/\nfunction isString( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof String ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object String]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a string\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*/\nfunction isString( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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* Test if a value is a string.\n*\n* @module @stdlib/assert-is-string\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' );\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 5 );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isObject;\n*\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 'beep' );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isString = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isString, 'isPrimitive', isPrimitive );\nsetReadOnly( isString, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// VARIABLES //\n\nvar RE_CHARS = /[-\\/\\\\^$*+?.()|[\\]{}]/g; // eslint-disable-line no-useless-escape\n\n\n// MAIN //\n\n/**\n* Escapes a regular expression string.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} first argument must be a string primitive\n* @returns {string} escaped string\n*\n* @example\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\nfunction rescape( str ) {\n\tvar len;\n\tvar s;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Check if the string starts with a forward slash...\n\tif ( str[ 0 ] === '/' ) {\n\t\t// Find the last forward slash...\n\t\tlen = str.length;\n\t\tfor ( i = len-1; i >= 0; i-- ) {\n\t\t\tif ( str[ i ] === '/' ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:\n\tif ( i === void 0 || i <= 0 ) {\n\t\treturn str.replace( RE_CHARS, '\\\\$&' );\n\t}\n\t// We need to de-construct the string...\n\ts = str.substring( 1, i );\n\n\t// Only escape the characters between the `/`:\n\ts = s.replace( RE_CHARS, '\\\\$&' );\n\n\t// Reassemble:\n\tstr = str[ 0 ] + s + str.substring( i );\n\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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* Escape a regular expression string or pattern.\n*\n* @module @stdlib/utils-escape-regexp-string\n*\n* @example\n* var rescape = require( '@stdlib/utils-escape-regexp-string' );\n*\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\n\n// MODULES //\n\nvar rescape = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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\nvar RE = /./;\n\n\n// EXPORTS //\n\nmodule.exports = RE;\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* Tests if a value is a boolean primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean primitive\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns false\n*/\nfunction isBoolean( value ) {\n\treturn ( typeof value === 'boolean' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Boolean.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean object\n*\n* @example\n* var bool = isBoolean( true );\n* // returns false\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Boolean ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Boolean]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a boolean\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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* Test if a value is a boolean.\n*\n* @module @stdlib/assert-is-boolean\n*\n* @example\n* var isBoolean = require( '@stdlib/assert-is-boolean' );\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* // Use interface to check for boolean primitives...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( true ) );\n* // returns false\n*\n* @example\n* // Use interface to check for boolean objects...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isObject;\n*\n* var bool = isBoolean( true );\n* // returns false\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isBoolean = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isBoolean, 'isPrimitive', isPrimitive );\nsetReadOnly( isBoolean, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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// MAIN //\n\n/**\n* Returns the global object using code generation.\n*\n* @private\n* @returns {Object} global object\n*/\nfunction getGlobal() {\n\treturn new Function( 'return this;' )(); // eslint-disable-line no-new-func\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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// MAIN //\n\nvar obj = ( typeof self === 'object' ) ? self : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof window === 'object' ) ? window : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof global === 'object' ) ? global : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar getThis = require( './codegen.js' );\nvar Self = require( './self.js' );\nvar Win = require( './window.js' );\nvar Global = require( './global.js' );\n\n\n// MAIN //\n\n/**\n* Returns the global object.\n*\n* ## Notes\n*\n* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.\n*\n* @param {boolean} [codegen=false] - boolean indicating whether to use code generation to resolve the global object\n* @throws {TypeError} must provide a boolean\n* @throws {Error} unable to resolve global object\n* @returns {Object} global object\n*\n* @example\n* var g = getGlobal();\n* // returns {...}\n*/\nfunction getGlobal( codegen ) {\n\tif ( arguments.length ) {\n\t\tif ( !isBoolean( codegen ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Must provide a boolean primitive. Value: `'+codegen+'`.' );\n\t\t}\n\t\tif ( codegen ) {\n\t\t\treturn getThis();\n\t\t}\n\t\t// Fall through...\n\t}\n\t// Case: browsers and web workers\n\tif ( Self ) {\n\t\treturn Self;\n\t}\n\t// Case: browsers\n\tif ( Win ) {\n\t\treturn Win;\n\t}\n\t// Case: Node.js\n\tif ( Global ) {\n\t\treturn Global;\n\t}\n\t// Case: unknown\n\tthrow new Error( 'unexpected error. Unable to resolve global object.' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar getGlobal = require( '@stdlib/utils-global' );\n\n\n// MAIN //\n\nvar root = getGlobal();\nvar nodeList = root.document && root.document.childNodes;\n\n\n// EXPORTS //\n\nmodule.exports = nodeList;\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* Return the global object.\n*\n* @module @stdlib/utils-global\n*\n* @example\n* var getGlobal = require( '@stdlib/utils-global' );\n*\n* var g = getGlobal();\n* // returns {...}\n*/\n\n// MODULES //\n\nvar getGlobal = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar typedarray = Int8Array; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = typedarray;\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\nvar RE = require( './fixtures/re.js' );\nvar nodeList = require( './fixtures/nodelist.js' );\nvar typedarray = require( './fixtures/typedarray.js' );\n\n\n// MAIN //\n\n/**\n* Checks whether a polyfill is needed when using the `typeof` operator.\n*\n* @private\n* @returns {boolean} boolean indicating whether a polyfill is needed\n*/\nfunction check() {\n\tif (\n\t\t// Chrome 1-12 returns 'function' for regular expression instances (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof):\n\t\ttypeof RE === 'function' ||\n\n\t\t// Safari 8 returns 'object' for typed array and weak map constructors (underscore #1929):\n\t\ttypeof typedarray === 'object' ||\n\n\t\t// PhantomJS 1.9 returns 'function' for `NodeList` instances (underscore #2236):\n\t\ttypeof nodeList === 'function'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\nfunction reFunctionName() {\n\treturn /^\\s*function\\s*([^(]*)/i;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @module @stdlib/regexp-function-name\n*\n* @example\n* var reFunctionName = require( '@stdlib/regexp-function-name' );\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reFunctionName = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reFunctionName, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\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\nvar reFunctionName = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Captures everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* Regular expression: `/^\\s*function\\s*([^(]*)/i`\n*\n* - `/^\\s*`\n* - Match zero or more spaces at beginning\n*\n* - `function`\n* - Match the word `function`\n*\n* - `\\s*`\n* - Match zero or more spaces after the word `function`\n*\n* - `()`\n* - Capture\n*\n* - `[^(]*`\n* - Match anything except a left parenthesis `(` zero or more times\n*\n* - `/i`\n* - ignore case\n*\n* @constant\n* @type {RegExp}\n* @default /^\\s*function\\s*([^(]*)/i\n*/\nvar RE_FUNCTION_NAME = reFunctionName();\n\n\n// EXPORTS //\n\nmodule.exports = RE_FUNCTION_NAME;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar f;\n\n\n// FUNCTIONS //\n\n/**\n* Tests if a value is an array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an array\n*\n* @example\n* var bool = isArray( [] );\n* // returns true\n*\n* @example\n* var bool = isArray( {} );\n* // returns false\n*/\nfunction isArray( value ) {\n\treturn ( nativeClass( value ) === '[object Array]' );\n}\n\n\n// MAIN //\n\nif ( Array.isArray ) {\n\tf = Array.isArray;\n} else {\n\tf = isArray;\n}\n\n\n// EXPORTS //\n\nmodule.exports = f;\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* Test if a value is an array.\n*\n* @module @stdlib/assert-is-array\n*\n* @example\n* var isArray = require( '@stdlib/assert-is-array' );\n*\n* var bool = isArray( [] );\n* // returns true\n*\n* bool = isArray( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isArray = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isArray;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Returns a function which tests if every element in an array passes a test condition.\n*\n* @param {Function} predicate - function to apply\n* @throws {TypeError} must provide a function\n* @returns {Function} an array function\n*\n* @example\n* var isOdd = require( '@stdlib/assert-is-odd' );\n*\n* var arr1 = [ 1, 3, 5, 7 ];\n* var arr2 = [ 3, 5, 8 ];\n*\n* var validate = arrayfcn( isOdd );\n*\n* var bool = validate( arr1 );\n* // returns true\n*\n* bool = validate( arr2 );\n* // returns false\n*/\nfunction arrayfcn( predicate ) {\n\tif ( typeof predicate !== 'function' ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a function. Value: `' + predicate + '`.' );\n\t}\n\treturn every;\n\n\t/**\n\t* Tests if every element in an array passes a test condition.\n\t*\n\t* @private\n\t* @param {*} value - value to test\n\t* @returns {boolean} boolean indicating whether a value is an array for which all elements pass a test condition\n\t*/\n\tfunction every( value ) {\n\t\tvar len;\n\t\tvar i;\n\t\tif ( !isArray( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tlen = value.length;\n\t\tif ( len === 0 ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( predicate( value[ i ] ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayfcn;\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* Tests if a value is object-like.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is object-like\n*\n* @example\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( [] );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( null );\n* // returns false\n*/\nfunction isObjectLike( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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* Test if a value is object-like.\n*\n* @module @stdlib/assert-is-object-like\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' );\n*\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* bool = isObjectLike( [] );\n* // returns true\n*\n* bool = isObjectLike( null );\n* // returns false\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' ).isObjectLikeArray;\n*\n* var bool = isObjectLike( [ {}, [] ] );\n* // returns true\n*\n* bool = isObjectLike( [ {}, '3.0' ] );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar arrayfun = require( '@stdlib/assert-tools-array-function' );\nvar isObjectLike = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( isObjectLike, 'isObjectLikeArray', arrayfun( isObjectLike ) );\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Buffer instance.\n*\n* @param {*} value - value to validate\n* @returns {boolean} boolean indicating if a value is a Buffer instance\n*\n* @example\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( new Buffer( [1,2,3,4] ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( {} );\n* // returns false\n*\n* @example\n* var v = isBuffer( [] );\n* // returns false\n*/\nfunction isBuffer( value ) {\n\treturn (\n\t\tisObjectLike( value ) &&\n\t\t(\n\t\t\t// eslint-disable-next-line no-underscore-dangle\n\t\t\tvalue._isBuffer || // for envs missing Object.prototype.constructor (e.g., Safari 5-7)\n\t\t\t(\n\t\t\t\tvalue.constructor &&\n\n\t\t\t\t// WARNING: `typeof` is not a foolproof check, as certain envs consider RegExp and NodeList instances to be functions\n\t\t\t\ttypeof value.constructor.isBuffer === 'function' &&\n\t\t\t\tvalue.constructor.isBuffer( value )\n\t\t\t)\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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* Test if a value is a Buffer instance.\n*\n* @module @stdlib/assert-is-buffer\n*\n* @example\n* var isBuffer = require( '@stdlib/assert-is-buffer' );\n*\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* v = isBuffer( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isBuffer = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar RE = require( '@stdlib/regexp-function-name' ).REGEXP;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\n\n\n// MAIN //\n\n/**\n* Determines the name of a value's constructor.\n*\n* @param {*} v - input value\n* @returns {string} name of a value's constructor\n*\n* @example\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* @example\n* var v = constructorName( 5 );\n* // returns 'Number'\n*\n* @example\n* var v = constructorName( null );\n* // returns 'Null'\n*\n* @example\n* var v = constructorName( undefined );\n* // returns 'Undefined'\n*\n* @example\n* var v = constructorName( function noop() {} );\n* // returns 'Function'\n*/\nfunction constructorName( v ) {\n\tvar match;\n\tvar name;\n\tvar ctor;\n\tname = nativeClass( v ).slice( 8, -1 );\n\tif ( (name === 'Object' || name === 'Error') && v.constructor ) {\n\t\tctor = v.constructor;\n\t\tif ( typeof ctor.name === 'string' ) {\n\t\t\treturn ctor.name;\n\t\t}\n\t\tmatch = RE.exec( ctor.toString() );\n\t\tif ( match ) {\n\t\t\treturn match[ 1 ];\n\t\t}\n\t}\n\tif ( isBuffer( v ) ) {\n\t\treturn 'Buffer';\n\t}\n\treturn name;\n}\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// NOTES //\n\n/*\n* Built-in `typeof` operator behavior:\n*\n* ```text\n* typeof null => 'object'\n* typeof undefined => 'undefined'\n* typeof 'a' => 'string'\n* typeof 5 => 'number'\n* typeof NaN => 'number'\n* typeof true => 'boolean'\n* typeof false => 'boolean'\n* typeof {} => 'object'\n* typeof [] => 'object'\n* typeof function foo(){} => 'function'\n* typeof function* foo(){} => 'object'\n* typeof Symbol() => 'symbol'\n* ```\n*\n*/\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\tvar type;\n\n\t// Address `typeof null` => `object` (see http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null):\n\tif ( v === null ) {\n\t\treturn 'null';\n\t}\n\ttype = typeof v;\n\n\t// If the `typeof` operator returned something other than `object`, we are done. Otherwise, we need to check for an internal class name or search for a constructor.\n\tif ( type === 'object' ) {\n\t\treturn ctorName( v ).toLowerCase();\n\t}\n\treturn type;\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine the name of a value's constructor.\n*\n* @module @stdlib/utils-constructor-name\n*\n* @example\n* var constructorName = require( '@stdlib/utils-constructor-name' );\n*\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* v = constructorName( {} );\n* // returns 'Object'\n*\n* v = constructorName( true );\n* // returns 'Boolean'\n*/\n\n// MODULES //\n\nvar constructorName = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\treturn ctorName( v ).toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine a value's type.\n*\n* @module @stdlib/utils-type-of\n*\n* @example\n* var typeOf = require( '@stdlib/utils-type-of' );\n*\n* var str = typeOf( 'a' );\n* // returns 'string'\n*\n* str = typeOf( 5 );\n* // returns 'number'\n*/\n\n// MODULES //\n\nvar usePolyfill = require( './check.js' );\nvar typeOf = require( './typeof.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main = ( usePolyfill() ) ? polyfill : typeOf;\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar typeOf = require( '@stdlib/utils-type-of' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a function.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a function\n*\n* @example\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\nfunction isFunction( value ) {\n\t// Note: cannot use `typeof` directly, as various browser engines incorrectly return `'function'` when operating on non-function objects, such as regular expressions and NodeLists.\n\treturn ( typeOf( value ) === 'function' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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* Test if a value is a function.\n*\n* @module @stdlib/assert-is-function\n*\n* @example\n* var isFunction = require( '@stdlib/assert-is-function' );\n*\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\n\n// MODULES //\n\nvar isFunction = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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\nvar exec = require( './exec.js' );\n\n\n// MAIN //\n\n/**\n* Attempts to call a `RegExp` method.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if able to call a `RegExp` method\n*/\nfunction test( value ) {\n\ttry {\n\t\texec.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar exec = RegExp.prototype.exec; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = exec;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2exec.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a regular expression.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a regular expression\n*\n* @example\n* var bool = isRegExp( /\\.+/ );\n* // returns true\n*\n* @example\n* var bool = isRegExp( {} );\n* // returns false\n*/\nfunction isRegExp( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof RegExp ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object RegExp]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isRegExp;\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\nvar rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument argument must be a string primitive or regular expression\n* @throws {TypeError} third argument must be a string primitive or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive or regular expression. Value: `' + search + '`.' );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( 'invalid argument. Third argument must be a string primitive or replacement function. Value: `' + newval + '`.' );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Constructor which returns a `Number` object.\n*\n* @module @stdlib/number-ctor\n*\n* @example\n* var Number = require( '@stdlib/number-ctor' );\n*\n* var v = new Number( 10.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar Number = require( './number.js' );\n\n\n// EXPORTS //\n\nmodule.exports = Number;\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// EXPORTS //\n\nmodule.exports = Number; // eslint-disable-line stdlib/require-globals\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Number.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar Number = require( '@stdlib/number-ctor' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\nfunction isNumber( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Number ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Number]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a number\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( null );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Test if a value is a number.\n*\n* @module @stdlib/assert-is-number\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' );\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( null );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isObject;\n*\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNumber, 'isPrimitive', isPrimitive );\nsetReadOnly( isNumber, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Double-precision floating-point positive infinity.\n*\n* @module @stdlib/constants-float64-pinf\n* @type {number}\n*\n* @example\n* var FLOAT64_PINF = require( '@stdlib/constants-float64-pinf' );\n* // returns Infinity\n*/\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point positive infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point positive infinity has the bit sequence\n*\n* ```binarystring\n* 0 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.POSITIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_PINF = Number.POSITIVE_INFINITY; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_PINF;\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* Double-precision floating-point negative infinity.\n*\n* @module @stdlib/constants-float64-ninf\n* @type {number}\n*\n* @example\n* var FLOAT64_NINF = require( '@stdlib/constants-float64-ninf' );\n* // returns -Infinity\n*/\n\n// MODULES //\n\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point negative infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point negative infinity has the bit sequence\n*\n* ```binarystring\n* 1 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.NEGATIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_NINF = Number.NEGATIVE_INFINITY;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_NINF;\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\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Tests if a finite double-precision floating-point number is an integer.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\treturn (floor(x) === x);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// TODO: implementation (?)\n\n/**\n* Rounds a double-precision floating-point number toward negative infinity.\n*\n* @param {number} x - input value\n* @returns {number} rounded value\n*\n* @example\n* var v = floor( -4.2 );\n* // returns -5.0\n*\n* @example\n* var v = floor( 9.99999 );\n* // returns 9.0\n*\n* @example\n* var v = floor( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = floor( NaN );\n* // returns NaN\n*/\nvar floor = Math.floor; // eslint-disable-line stdlib/no-builtin-math\n\n\n// EXPORTS //\n\nmodule.exports = floor;\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* Test if a finite double-precision floating-point number is an integer.\n*\n* @module @stdlib/math-base-assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/math-base-assert-is-integer' );\n*\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* bool = isInteger( 3.14 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isInteger = require( './is_integer.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar isInt = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests if a number primitive is an integer value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a number primitive is an integer value\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tvalue < PINF &&\n\t\tvalue > NINF &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having an integer value\n*\n* @example\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having an integer value\n*\n* @example\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an integer\n*\n* @example\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isInteger( -3.14 );\n* // returns false\n*\n* @example\n* var bool = isInteger( null );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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* Test if a value is an integer.\n*\n* @module @stdlib/assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/assert-is-integer' );\n*\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isInteger( -3.14 );\n* // returns false\n*\n* bool = isInteger( null );\n* // returns false\n*\n* @example\n* // Use interface to check for integer primitives...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n*\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*\n* @example\n* // Use interface to check for integer objects...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n*\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue.valueOf() >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a nonnegative integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a nonnegative integer\n*\n* @example\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( null );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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* Test if a value is a nonnegative integer.\n*\n* @module @stdlib/assert-is-nonnegative-integer\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' );\n*\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* bool = isNonNegativeInteger( null );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isObject;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNonNegativeInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isNonNegativeInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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// MAIN //\n\nvar getProto = Object.getPrototypeOf;\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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* Returns the value of the `__proto__` property.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {*} value of `__proto__` property\n*/\nfunction getProto( obj ) {\n\t// eslint-disable-next-line no-proto\n\treturn obj.__proto__;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar getProto = require( './proto.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {(Object|null)} prototype\n*/\nfunction getPrototypeOf( obj ) {\n\tvar proto = getProto( obj );\n\tif ( proto || proto === null ) {\n\t\treturn proto;\n\t}\n\tif ( nativeClass( obj.constructor ) === '[object Function]' ) {\n\t\t// May break if the constructor has been tampered with...\n\t\treturn obj.constructor.prototype;\n\t}\n\tif ( obj instanceof Object ) {\n\t\treturn Object.prototype;\n\t}\n\t// Return `null` for objects created via `Object.create( null )`. Also return `null` for cross-realm objects on browsers that lack `__proto__` support, such as IE < 11.\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar builtin = require( './native.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar getProto;\nif ( isFunction( Object.getPrototypeOf ) ) {\n\tgetProto = builtin;\n} else {\n\tgetProto = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar getProto = require( './detect.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @param {*} value - input value\n* @returns {(Object|null)} prototype\n*\n* @example\n* var proto = getPrototypeOf( {} );\n* // returns {}\n*/\nfunction getPrototypeOf( value ) {\n\tif (\n\t\tvalue === null ||\n\t\tvalue === void 0\n\t) {\n\t\treturn null;\n\t}\n\t// In order to ensure consistent ES5/ES6 behavior, cast input value to an object (strings, numbers, booleans); ES5 `Object.getPrototypeOf` throws when provided primitives and ES6 `Object.getPrototypeOf` casts:\n\tvalue = Object( value );\n\n\treturn getProto( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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* Return the prototype of a provided object.\n*\n* @module @stdlib/utils-get-prototype-of\n*\n* @example\n* var getPrototype = require( '@stdlib/utils-get-prototype-of' );\n*\n* var proto = getPrototype( {} );\n* // returns {}\n*/\n\n// MODULES //\n\nvar getPrototype = require( './get_prototype_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getPrototype;\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\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an `Error` object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `Error` object\n*\n* @example\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isError( {} );\n* // returns false\n*/\nfunction isError( value ) {\n\tif ( typeof value !== 'object' || value === null ) {\n\t\treturn false;\n\t}\n\t// Check for `Error` objects from the same realm (same Node.js `vm` or same `Window` object)...\n\tif ( value instanceof Error ) {\n\t\treturn true;\n\t}\n\t// Walk the prototype tree until we find an object having the desired native class...\n\twhile ( value ) {\n\t\tif ( nativeClass( value ) === '[object Error]' ) {\n\t\t\treturn true;\n\t\t}\n\t\tvalue = getPrototypeOf( value );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isError;\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* Test if a value is an `Error` object.\n*\n* @module @stdlib/assert-is-error\n*\n* @example\n* var isError = require( '@stdlib/assert-is-error' );\n*\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* bool = isError( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isError = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isError;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to parse a regular expression string.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*/\nfunction reRegExp() {\n\treturn /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/; // eslint-disable-line no-useless-escape\n}\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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* Return a regular expression to parse a regular expression string.\n*\n* @module @stdlib/regexp-regexp\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var parts = RE_REGEXP.exec( '/^.*$/ig' );\n* // returns [ '/^.*$/ig', '^.*$', 'ig', 'index': 0, 'input': '/^.*$/ig' ]\n*/\n\n// MAIN //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reRegExp = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reRegExp, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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\nvar reRegExp = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Matches parts of a regular expression string.\n*\n* Regular expression: `/^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/`\n*\n* - `/^\\/`\n* - match a string that begins with a `/`\n*\n* - `()`\n* - capture\n*\n* - `(?:)+`\n* - capture, but do not remember, a group of characters which occur one or more times\n*\n* - `\\\\\\/`\n* - match the literal `\\/`\n*\n* - `|`\n* - OR\n*\n* - `[^\\/]`\n* - anything which is not the literal `\\/`\n*\n* - `\\/`\n* - match the literal `/`\n*\n* - `([imgy]*)`\n* - capture any characters matching `imgy` occurring zero or more times\n*\n* - `$/`\n* - string end\n*\n*\n* @constant\n* @type {RegExp}\n* @default /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/\n*/\nvar RE_REGEXP = reRegExp();\n\n\n// EXPORTS //\n\nmodule.exports = RE_REGEXP;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar reRegExp = require( '@stdlib/regexp-regexp' );\n\n\n// MAIN //\n\n/**\n* Parses a regular expression string and returns a new regular expression.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} must provide a regular expression string\n* @returns {(RegExp|null)} regular expression or null\n*\n* @example\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\nfunction reFromString( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Capture the regular expression pattern and any flags:\n\tstr = reRegExp().exec( str );\n\n\t// Create a new regular expression:\n\treturn ( str ) ? new RegExp( str[1], str[2] ) : null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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* Create a regular expression from a regular expression string.\n*\n* @module @stdlib/utils-regexp-from-string\n*\n* @example\n* var reFromString = require( '@stdlib/utils-regexp-from-string' );\n*\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\n\n// MODULES //\n\nvar reFromString = require( './from_string.js' );\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is `NaN`.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 7.0 );\n* // returns false\n*/\nfunction isnan( x ) {\n\treturn ( x !== x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a `NaN` number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a `NaN` number primitive\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a double-precision floating-point numeric value is `NaN`.\n*\n* @module @stdlib/math-base-assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/math-base-assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 7.0 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isnan = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a value of `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a value of `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( null );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a value is `NaN`.\n*\n* @module @stdlib/assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( null );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isObject;\n*\n* var bool = isnan( NaN );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isnan = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isnan, 'isPrimitive', isPrimitive );\nsetReadOnly( isnan, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a collection.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is a collection\n*\n* @example\n* var bool = isCollection( [] );\n* // returns true\n*\n* @example\n* var bool = isCollection( {} );\n* // returns false\n*/\nfunction isCollection( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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\nvar isnan = require( '@stdlib/assert-is-nan' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Returns the first index at which a given element can be found.\n*\n* @param {ArrayLike} arr - array-like object\n* @param {*} searchElement - element to find\n* @param {integer} [fromIndex] - starting index (if negative, the start index is determined relative to last element)\n* @throws {TypeError} must provide an array-like object\n* @throws {TypeError} `fromIndex` must be an integer\n* @returns {integer} index or -1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 5 );\n* // returns -1\n*\n* @example\n* // Using a `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* @example\n* // `fromIndex` which exceeds `array` length:\n* var arr = [ 1, 2, 3, 4, 2, 5 ];\n* var idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* @example\n* // Negative `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* var idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* @example\n* // Negative `fromIndex` exceeding input `array` length:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* @example\n* // Array-like objects:\n* var str = 'bebop';\n* var idx = indexOf( str, 'o' );\n* // returns 3\n*/\nfunction indexOf( arr, searchElement, fromIndex ) {\n\tvar len;\n\tvar i;\n\tif ( !isCollection( arr ) && !isString( arr ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array-like object. Value: `' + arr + '`.' );\n\t}\n\tlen = arr.length;\n\tif ( len === 0 ) {\n\t\treturn -1;\n\t}\n\tif ( arguments.length === 3 ) {\n\t\tif ( !isInteger( fromIndex ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `fromIndex` must be an integer. Value: `' + fromIndex + '`.' );\n\t\t}\n\t\tif ( fromIndex >= 0 ) {\n\t\t\tif ( fromIndex >= len ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\ti = fromIndex;\n\t\t} else {\n\t\t\ti = len + fromIndex;\n\t\t\tif ( i < 0 ) {\n\t\t\t\ti = 0;\n\t\t\t}\n\t\t}\n\t} else {\n\t\ti = 0;\n\t}\n\t// Check for `NaN`...\n\tif ( isnan( searchElement ) ) {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( isnan( arr[i] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( arr[ i ] === searchElement ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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* Maximum length of a typed array.\n*\n* @module @stdlib/constants-array-max-typed-array-length\n*\n* @example\n* var MAX_TYPED_ARRAY_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n* // returns 9007199254740991\n*/\n\n// MAIN //\n\n/**\n* Maximum length of a typed array.\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n*/\nvar MAX_TYPED_ARRAY_LENGTH = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = MAX_TYPED_ARRAY_LENGTH;\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* Return the first index at which a given element can be found.\n*\n* @module @stdlib/utils-index-of\n*\n* @example\n* var indexOf = require( '@stdlib/utils-index-of' );\n*\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* arr = [ 4, 3, 2, 1 ];\n* idx = indexOf( arr, 5 );\n* // returns -1\n*\n* // Using a `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* // `fromIndex` which exceeds `array` length:\n* arr = [ 1, 2, 3, 4, 2, 5 ];\n* idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* // Negative `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* // Negative `fromIndex` exceeding input `array` length:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* // Array-like objects:\n* var str = 'bebop';\n* idx = indexOf( str, 'o' );\n* // returns 3\n*/\n\n// MODULES //\n\nvar indexOf = require( './index_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.keys()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\treturn Object.keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar keys = require( './builtin.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests the built-in `Object.keys()` implementation when provided `arguments`.\n*\n* @private\n* @returns {boolean} boolean indicating whether the built-in implementation returns the expected number of keys\n*/\nfunction test() {\n\treturn ( keys( arguments ) || '' ).length !== 2;\n}\n\n\n// MAIN //\n\n/**\n* Tests whether the built-in `Object.keys()` implementation supports providing `arguments` as an input value.\n*\n* ## Notes\n*\n* - Safari 5.0 does **not** support `arguments` as an input value.\n*\n* @private\n* @returns {boolean} boolean indicating whether a built-in implementation supports `arguments`\n*/\nfunction check() {\n\treturn test( 1, 2 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\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// MAIN //\n\nvar bool = ( typeof Object.keys !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn ( nativeClass( value ) === '[object Arguments]' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( './main.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment returns the expected internal class of the `arguments` object.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment behaves as expected\n*\n* @example\n* var bool = detect();\n* // returns \n*/\nfunction detect() {\n\treturn isArguments( arguments );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnum = require( './native.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment has a bug where String indices are not detected as \"enumerable\" properties. Observed in Node v0.10.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment has the bug\n*/\nfunction detect() {\n\treturn !isEnum.call( 'beep', '0' );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @private\n* @name isEnumerableProperty\n* @type {Function}\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nvar isEnumerableProperty = Object.prototype.propertyIsEnumerable;\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar isString = require( '@stdlib/assert-is-string' );\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isEnum = require( './native.js' );\nvar hasStringEnumBug = require( './has_string_enumerability_bug.js' );\n\n\n// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nfunction isEnumerableProperty( value, property ) {\n\tvar bool;\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\tbool = isEnum.call( value, property );\n\tif ( !bool && hasStringEnumBug && isString( value ) ) {\n\t\t// Note: we only check for indices, as properties attached to a `String` object are properly detected as enumerable above.\n\t\tproperty = +property;\n\t\treturn (\n\t\t\t!isnan( property ) &&\n\t\t\tisInteger( property ) &&\n\t\t\tproperty >= 0 &&\n\t\t\tproperty < value.length\n\t\t);\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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* Test whether an object's own property is enumerable.\n*\n* @module @stdlib/assert-is-enumerable-property\n*\n* @example\n* var isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\n\n// MODULES //\n\nvar isEnumerableProperty = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-uint32-max' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object' &&\n\t\t!isArray( value ) &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH &&\n\t\thasOwnProp( value, 'callee' ) &&\n\t\t!isEnumerableProperty( value, 'callee' )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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* Test if a value is an `arguments` object.\n*\n* @module @stdlib/assert-is-arguments\n*\n* @example\n* var isArguments = require( '@stdlib/assert-is-arguments' );\n*\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* bool = isArguments( [] );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasArgumentsClass = require( './detect.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar isArguments;\nif ( hasArgumentsClass ) {\n\tisArguments = main;\n} else {\n\tisArguments = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar builtin = require( './builtin.js' );\n\n\n// VARIABLES //\n\nvar slice = Array.prototype.slice;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tif ( isArguments( value ) ) {\n\t\treturn builtin( slice.call( value ) );\n\t}\n\treturn builtin( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* No operation.\n*\n* @example\n* noop();\n* // ...does nothing.\n*/\nfunction noop() {\n\t// Empty function...\n}\n\n\n// EXPORTS //\n\nmodule.exports = noop;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar noop = require( '@stdlib/utils-noop' );\n\n\n// MAIN //\n\n// Note: certain environments treat an object's prototype as enumerable, which, as a matter of convention, it shouldn't be...\nvar bool = isEnumerableProperty( noop, 'prototype' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n\n\n// VARIABLES //\n\nvar obj = {\n\t'toString': null\n};\n\n\n// MAIN //\n\n// Note: certain environments don't allow enumeration of overwritten properties which are considered non-enumerable...\nvar bool = !isEnumerableProperty( obj, 'toString' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests whether a value equals the prototype of its constructor.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction isConstructorPrototype( value ) {\n\treturn ( value.constructor && value.constructor.prototype === value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isConstructorPrototype;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar EXCLUDED_KEYS = require( './excluded_keys.json' );\nvar win = require( './window.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Determines whether an environment throws when comparing to the prototype of a value's constructor (e.g., [IE9][1]).\n*\n* [1]: https://stackoverflow.com/questions/7688070/why-is-comparing-the-constructor-property-of-two-windows-unreliable\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment is buggy\n*/\nfunction check() {\n\tvar k;\n\tif ( typeOf( win ) === 'undefined' ) {\n\t\treturn false;\n\t}\n\tfor ( k in win ) { // eslint-disable-line guard-for-in\n\t\ttry {\n\t\t\tif (\n\t\t\t\tindexOf( EXCLUDED_KEYS, k ) === -1 &&\n\t\t\t\thasOwnProp( win, k ) &&\n\t\t\t\twin[ k ] !== null &&\n\t\t\t\ttypeOf( win[ k ] ) === 'object'\n\t\t\t) {\n\t\t\t\tisConstructorPrototype( win[ k ] );\n\t\t\t}\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// MAIN //\n\nbool = check();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\nvar w = ( typeof window === 'undefined' ) ? void 0 : window;\n\n\n// EXPORTS //\n\nmodule.exports = w;\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// MAIN //\n\nvar bool = ( typeof window !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar hasAutomationEqualityBug = require( './has_automation_equality_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar HAS_WINDOW = require( './has_window.js' );\n\n\n// MAIN //\n\n/**\n* Wraps the test for constructor prototype equality to accommodate buggy environments (e.g., environments which throw when testing equality).\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction wrapper( value ) {\n\tif ( HAS_WINDOW === false && !hasAutomationEqualityBug ) {\n\t\treturn isConstructorPrototype( value );\n\t}\n\ttry {\n\t\treturn isConstructorPrototype( value );\n\t} catch ( error ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = wrapper;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar HAS_ENUM_PROTO_BUG = require( './has_enumerable_prototype_bug.js' );\nvar HAS_NON_ENUM_PROPS_BUG = require( './has_non_enumerable_properties_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype_wrapper.js' );\nvar NON_ENUMERABLE = require( './non_enumerable.json' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tvar skipConstructor;\n\tvar skipPrototype;\n\tvar isFcn;\n\tvar out;\n\tvar k;\n\tvar p;\n\tvar i;\n\n\tout = [];\n\tif ( isArguments( value ) ) {\n\t\t// Account for environments which treat `arguments` differently...\n\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\tout.push( i.toString() );\n\t\t}\n\t\t// Note: yes, we are precluding the `arguments` array-like object from having other enumerable properties; however, this should (1) be very rare and (2) not be encouraged (e.g., doing something like `arguments.a = 'b'`; in certain engines directly manipulating the `arguments` value results in automatic de-optimization).\n\t\treturn out;\n\t}\n\tif ( typeof value === 'string' ) {\n\t\t// Account for environments which do not treat string character indices as \"own\" properties...\n\t\tif ( value.length > 0 && !hasOwnProp( value, '0' ) ) {\n\t\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\t\tout.push( i.toString() );\n\t\t\t}\n\t\t}\n\t} else {\n\t\tisFcn = ( typeof value === 'function' );\n\t\tif ( isFcn === false && !isObjectLike( value ) ) {\n\t\t\treturn out;\n\t\t}\n\t\tskipPrototype = ( HAS_ENUM_PROTO_BUG && isFcn );\n\t}\n\tfor ( k in value ) {\n\t\tif ( !( skipPrototype && k === 'prototype' ) && hasOwnProp( value, k ) ) {\n\t\t\tout.push( String( k ) );\n\t\t}\n\t}\n\tif ( HAS_NON_ENUM_PROPS_BUG ) {\n\t\tskipConstructor = isConstructorPrototype( value );\n\t\tfor ( i = 0; i < NON_ENUMERABLE.length; i++ ) {\n\t\t\tp = NON_ENUMERABLE[ i ];\n\t\t\tif ( !( skipConstructor && p === 'constructor' ) && hasOwnProp( value, p ) ) {\n\t\t\t\tout.push( String( p ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar hasArgumentsBug = require( './has_arguments_bug.js' );\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar wrapper = require( './builtin_wrapper.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @name keys\n* @type {Function}\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nvar keys;\nif ( HAS_BUILTIN ) {\n\tif ( hasArgumentsBug() ) {\n\t\tkeys = wrapper;\n\t} else {\n\t\tkeys = builtin;\n\t}\n} else {\n\tkeys = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* Return an array of an object's own enumerable property names.\n*\n* @module @stdlib/utils-keys\n*\n* @example\n* var keys = require( '@stdlib/utils-keys' );\n*\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\n\n// MODULES //\n\nvar keys = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyNames !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyNames = Object.getOwnPropertyNames;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn propertyNames( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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\nvar keys = require( '@stdlib/utils-keys' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n* - In environments lacking support for `Object.getOwnPropertyNames()`, property descriptors are unavailable, and thus all properties can be safely assumed to be enumerable. Hence, we can defer to calling `Object.keys`, which retrieves all own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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* Return an array of an object's own enumerable and non-enumerable property names.\n*\n* @module @stdlib/utils-property-names\n*\n* @example\n* var getOwnPropertyNames = require( '@stdlib/utils-property-names' );\n*\n* var keys = getOwnPropertyNames({\n* 'foo': 'bar',\n* 'beep': 'boop'\n* });\n* // e.g., returns [ 'foo', 'beep' ]\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyDescriptor !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyDescriptor = Object.getOwnPropertyDescriptor;\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tvar desc;\n\tif ( value === null || value === void 0 ) {\n\t\treturn null;\n\t}\n\tdesc = propertyDescriptor( value, property );\n\treturn ( desc === void 0 ) ? null : desc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n* - In environments lacking `Object.getOwnPropertyDescriptor()` support, property descriptors do not exist. In non-supporting environment, if an object has a provided property, this function returns a descriptor object equivalent to that returned in a supporting environment; otherwise, the function returns `null`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tif ( hasOwnProp( value, property ) ) {\n\t\treturn {\n\t\t\t'configurable': true,\n\t\t\t'enumerable': true,\n\t\t\t'writable': true,\n\t\t\t'value': value[ property ]\n\t\t};\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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* Return a property descriptor for an object's own property.\n*\n* @module @stdlib/utils-property-descriptor\n*\n* @example\n* var getOwnPropertyDescriptor = require( '@stdlib/utils-property-descriptor' );\n*\n* var obj = {\n* 'foo': 'bar',\n* 'beep': 'boop'\n* };\n*\n* var keys = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':'bar'}\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// TODO: write (browser) polyfill\n\n// MAIN //\n\n/**\n* Buffer constructor.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Buffer constructor.\n*\n* @module @stdlib/buffer-ctor\n*\n* @example\n* var ctor = require( '@stdlib/buffer-ctor' );\n*\n* var b = new ctor( [ 1, 2, 3, 4 ] );\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\nvar main = require( './buffer.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasNodeBufferSupport() ) {\n\tctor = main;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = require( 'buffer' ).Buffer; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\nvar bool = isFunction( Buffer.from );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn Buffer.from( buffer );\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn new Buffer( buffer ); // eslint-disable-line no-buffer-constructor\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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* Copy buffer data to a new `Buffer` instance.\n*\n* @module @stdlib/buffer-from-buffer\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n* var copyBuffer = require( '@stdlib/buffer-from-buffer' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = copyBuffer( b1 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFrom = require( './has_from.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar copyBuffer;\nif ( hasFrom ) {\n\tcopyBuffer = main;\n} else {\n\tcopyBuffer = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt8Array = ( typeof Int8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int8Array\n*\n* @example\n* var bool = isInt8Array( new Int8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt8Array( [] );\n* // returns false\n*/\nfunction isInt8Array( value ) {\n\treturn (\n\t\t( hasInt8Array && value instanceof Int8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt8Array;\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// MAIN //\n\nvar main = ( typeof Int8Array === 'function' ) ? Int8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt8Array = require( '@stdlib/assert-is-int8array' );\nvar INT8_MAX = require( '@stdlib/constants-int8-max' );\nvar INT8_MIN = require( '@stdlib/constants-int8-min' );\nvar GlobalInt8Array = require( './int8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int8Array` support\n*\n* @example\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\nfunction hasInt8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt8Array( [ 1, 3.14, -3.14, INT8_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT8_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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* Minimum signed 8-bit integer.\n*\n* @module @stdlib/constants-int8-min\n* @type {integer32}\n*\n* @example\n* var INT8_MIN = require( '@stdlib/constants-int8-min' );\n* // returns -128\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 8-bit integer.\n*\n* ## Notes\n*\n* The number is given by\n*\n* ```tex\n* -(2^{7})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -128\n*/\nvar INT8_MIN = -128|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT8_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int8\n*\n* @example\n* var ctor = require( '@stdlib/array-int8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\nvar builtin = require( './int8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int8Array === 'function' ) ? Int8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int8Array` support.\n*\n* @module @stdlib/assert-has-int8array-support\n*\n* @example\n* var hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\n*\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8Array = ( typeof Uint8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8Array\n*\n* @example\n* var bool = isUint8Array( new Uint8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8Array( [] );\n* // returns false\n*/\nfunction isUint8Array( value ) {\n\treturn (\n\t\t( hasUint8Array && value instanceof Uint8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8Array;\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// MAIN //\n\nvar main = ( typeof Uint8Array === 'function' ) ? Uint8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8Array = require( '@stdlib/assert-is-uint8array' );\nvar UINT8_MAX = require( '@stdlib/constants-uint8-max' );\nvar GlobalUint8Array = require( './uint8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8Array` support\n*\n* @example\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\nfunction hasUint8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT8_MAX+1, UINT8_MAX+2 ];\n\t\tarr = new GlobalUint8Array( arr );\n\t\tbool = (\n\t\t\tisUint8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT8_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint8\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\nvar builtin = require( './uint8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8Array === 'function' ) ? Uint8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8Array` support.\n*\n* @module @stdlib/assert-has-uint8array-support\n*\n* @example\n* var hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\n*\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8ClampedArray = ( typeof Uint8ClampedArray === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8ClampedArray.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8ClampedArray\n*\n* @example\n* var bool = isUint8ClampedArray( new Uint8ClampedArray( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8ClampedArray( [] );\n* // returns false\n*/\nfunction isUint8ClampedArray( value ) {\n\treturn (\n\t\t( hasUint8ClampedArray && value instanceof Uint8ClampedArray ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8ClampedArray]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8ClampedArray;\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// MAIN //\n\nvar main = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8ClampedArray = require( '@stdlib/assert-is-uint8clampedarray' );\nvar GlobalUint8ClampedArray = require( './uint8clampedarray.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8ClampedArray` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8ClampedArray` support\n*\n* @example\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\nfunction hasUint8ClampedArraySupport() { // eslint-disable-line id-length\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8ClampedArray !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalUint8ClampedArray( [ -1, 0, 1, 3.14, 4.99, 255, 256 ] );\n\t\tbool = (\n\t\t\tisUint8ClampedArray( arr ) &&\n\t\t\tarr[ 0 ] === 0 && // clamped\n\t\t\tarr[ 1 ] === 0 &&\n\t\t\tarr[ 2 ] === 1 &&\n\t\t\tarr[ 3 ] === 3 && // round to nearest\n\t\t\tarr[ 4 ] === 5 && // round to nearest\n\t\t\tarr[ 5 ] === 255 &&\n\t\t\tarr[ 6 ] === 255 // clamped\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @module @stdlib/array-uint8c\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8c' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' ); // eslint-disable-line id-length\nvar builtin = require( './uint8clampedarray.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ClampedArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8ClampedArray` support.\n*\n* @module @stdlib/assert-has-uint8clampedarray-support\n*\n* @example\n* var hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' );\n*\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt16Array = ( typeof Int16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int16Array\n*\n* @example\n* var bool = isInt16Array( new Int16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt16Array( [] );\n* // returns false\n*/\nfunction isInt16Array( value ) {\n\treturn (\n\t\t( hasInt16Array && value instanceof Int16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt16Array;\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// MAIN //\n\nvar main = ( typeof Int16Array === 'function' ) ? Int16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt16Array = require( '@stdlib/assert-is-int16array' );\nvar INT16_MAX = require( '@stdlib/constants-int16-max' );\nvar INT16_MIN = require( '@stdlib/constants-int16-min' );\nvar GlobalInt16Array = require( './int16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int16Array` support\n*\n* @example\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\nfunction hasInt16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt16Array( [ 1, 3.14, -3.14, INT16_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT16_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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* Minimum signed 16-bit integer.\n*\n* @module @stdlib/constants-int16-min\n* @type {integer32}\n*\n* @example\n* var INT16_MIN = require( '@stdlib/constants-int16-min' );\n* // returns -32768\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 16-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{15})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 1000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -32768\n*/\nvar INT16_MIN = -32768|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT16_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int16\n*\n* @example\n* var ctor = require( '@stdlib/array-int16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\nvar builtin = require( './int16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int16Array === 'function' ) ? Int16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int16Array` support.\n*\n* @module @stdlib/assert-has-int16array-support\n*\n* @example\n* var hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\n*\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint16Array = ( typeof Uint16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint16Array\n*\n* @example\n* var bool = isUint16Array( new Uint16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint16Array( [] );\n* // returns false\n*/\nfunction isUint16Array( value ) {\n\treturn (\n\t\t( hasUint16Array && value instanceof Uint16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint16Array;\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// MAIN //\n\nvar main = ( typeof Uint16Array === 'function' ) ? Uint16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint16Array = require( '@stdlib/assert-is-uint16array' );\nvar UINT16_MAX = require( '@stdlib/constants-uint16-max' );\nvar GlobalUint16Array = require( './uint16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint16Array` support\n*\n* @example\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\nfunction hasUint16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT16_MAX+1, UINT16_MAX+2 ];\n\t\tarr = new GlobalUint16Array( arr );\n\t\tbool = (\n\t\t\tisUint16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT16_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 16-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint16\n*\n* @example\n* var ctor = require( '@stdlib/array-uint16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\nvar builtin = require( './uint16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint16Array === 'function' ) ? Uint16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint16Array` support.\n*\n* @module @stdlib/assert-has-uint16array-support\n*\n* @example\n* var hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\n*\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt32Array = ( typeof Int32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int32Array\n*\n* @example\n* var bool = isInt32Array( new Int32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt32Array( [] );\n* // returns false\n*/\nfunction isInt32Array( value ) {\n\treturn (\n\t\t( hasInt32Array && value instanceof Int32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt32Array;\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// MAIN //\n\nvar main = ( typeof Int32Array === 'function' ) ? Int32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt32Array = require( '@stdlib/assert-is-int32array' );\nvar INT32_MAX = require( '@stdlib/constants-int32-max' );\nvar INT32_MIN = require( '@stdlib/constants-int32-min' );\nvar GlobalInt32Array = require( './int32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int32Array` support\n*\n* @example\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\nfunction hasInt32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt32Array( [ 1, 3.14, -3.14, INT32_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT32_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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* Minimum signed 32-bit integer.\n*\n* @module @stdlib/constants-int32-min\n* @type {integer32}\n*\n* @example\n* var INT32_MIN = require( '@stdlib/constants-int32-min' );\n* // returns -2147483648\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 32-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{31})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -2147483648\n*/\nvar INT32_MIN = -2147483648|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT32_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int32\n*\n* @example\n* var ctor = require( '@stdlib/array-int32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\nvar builtin = require( './int32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int32Array === 'function' ) ? Int32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int32Array` support.\n*\n* @module @stdlib/assert-has-int32array-support\n*\n* @example\n* var hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\n*\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint32Array = ( typeof Uint32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint32Array\n*\n* @example\n* var bool = isUint32Array( new Uint32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint32Array( [] );\n* // returns false\n*/\nfunction isUint32Array( value ) {\n\treturn (\n\t\t( hasUint32Array && value instanceof Uint32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint32Array;\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// MAIN //\n\nvar main = ( typeof Uint32Array === 'function' ) ? Uint32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint32Array = require( '@stdlib/assert-is-uint32array' );\nvar UINT32_MAX = require( '@stdlib/constants-uint32-max' );\nvar GlobalUint32Array = require( './uint32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint32Array` support\n*\n* @example\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\nfunction hasUint32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT32_MAX+1, UINT32_MAX+2 ];\n\t\tarr = new GlobalUint32Array( arr );\n\t\tbool = (\n\t\t\tisUint32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT32_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 32-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint32\n*\n* @example\n* var ctor = require( '@stdlib/array-uint32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\nvar builtin = require( './uint32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint32Array === 'function' ) ? Uint32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint32Array` support.\n*\n* @module @stdlib/assert-has-uint32array-support\n*\n* @example\n* var hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\n*\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat32Array = ( typeof Float32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float32Array\n*\n* @example\n* var bool = isFloat32Array( new Float32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat32Array( [] );\n* // returns false\n*/\nfunction isFloat32Array( value ) {\n\treturn (\n\t\t( hasFloat32Array && value instanceof Float32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat32Array;\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// MAIN //\n\nvar main = ( typeof Float32Array === 'function' ) ? Float32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat32Array = require( '@stdlib/assert-is-float32array' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar GlobalFloat32Array = require( './float32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float32Array` support\n*\n* @example\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\nfunction hasFloat32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat32Array( [ 1.0, 3.14, -3.14, 5.0e40 ] );\n\t\tbool = (\n\t\t\tisFloat32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.140000104904175 &&\n\t\t\tarr[ 2 ] === -3.140000104904175 &&\n\t\t\tarr[ 3 ] === PINF\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of single-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float32\n*\n* @example\n* var ctor = require( '@stdlib/array-float32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\nvar builtin = require( './float32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float32Array === 'function' ) ? Float32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float32Array` support.\n*\n* @module @stdlib/assert-has-float32array-support\n*\n* @example\n* var hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\n*\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat64Array = ( typeof Float64Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float64Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float64Array\n*\n* @example\n* var bool = isFloat64Array( new Float64Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat64Array( [] );\n* // returns false\n*/\nfunction isFloat64Array( value ) {\n\treturn (\n\t\t( hasFloat64Array && value instanceof Float64Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float64Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat64Array;\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// MAIN //\n\nvar main = ( typeof Float64Array === 'function' ) ? Float64Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat64Array = require( '@stdlib/assert-is-float64array' );\nvar GlobalFloat64Array = require( './float64array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float64Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float64Array` support\n*\n* @example\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\nfunction hasFloat64ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat64Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat64Array( [ 1.0, 3.14, -3.14, NaN ] );\n\t\tbool = (\n\t\t\tisFloat64Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.14 &&\n\t\t\tarr[ 2 ] === -3.14 &&\n\t\t\tarr[ 3 ] !== arr[ 3 ]\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of double-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float64\n*\n* @example\n* var ctor = require( '@stdlib/array-float64' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\nvar builtin = require( './float64array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat64ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float64Array === 'function' ) ? Float64Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float64Array` support.\n*\n* @module @stdlib/assert-has-float64array-support\n*\n* @example\n* var hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\n*\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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\nvar Int8Array = require( '@stdlib/array-int8' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar Uint8ClampedArray = require( '@stdlib/array-uint8c' );\nvar Int16Array = require( '@stdlib/array-int16' );\nvar Uint16Array = require( '@stdlib/array-uint16' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar Uint32Array = require( '@stdlib/array-uint32' );\nvar Float32Array = require( '@stdlib/array-float32' );\nvar Float64Array = require( '@stdlib/array-float64' );\n\n\n// VARIABLES //\n\nvar hash;\n\n\n// FUNCTIONS //\n\n/**\n* Copies an `Int8Array`.\n*\n* @private\n* @param {Int8Array} arr - array to copy\n* @returns {Int8Array} new array\n*/\nfunction int8array( arr ) {\n\treturn new Int8Array( arr );\n}\n\n/**\n* Copies a `Uint8Array`.\n*\n* @private\n* @param {Uint8Array} arr - array to copy\n* @returns {Uint8Array} new array\n*/\nfunction uint8array( arr ) {\n\treturn new Uint8Array( arr );\n}\n\n/**\n* Copies a `Uint8ClampedArray`.\n*\n* @private\n* @param {Uint8ClampedArray} arr - array to copy\n* @returns {Uint8ClampedArray} new array\n*/\nfunction uint8clampedarray( arr ) {\n\treturn new Uint8ClampedArray( arr );\n}\n\n/**\n* Copies an `Int16Array`.\n*\n* @private\n* @param {Int16Array} arr - array to copy\n* @returns {Int16Array} new array\n*/\nfunction int16array( arr ) {\n\treturn new Int16Array( arr );\n}\n\n/**\n* Copies a `Uint16Array`.\n*\n* @private\n* @param {Uint16Array} arr - array to copy\n* @returns {Uint16Array} new array\n*/\nfunction uint16array( arr ) {\n\treturn new Uint16Array( arr );\n}\n\n/**\n* Copies an `Int32Array`.\n*\n* @private\n* @param {Int32Array} arr - array to copy\n* @returns {Int32Array} new array\n*/\nfunction int32array( arr ) {\n\treturn new Int32Array( arr );\n}\n\n/**\n* Copies a `Uint32Array`.\n*\n* @private\n* @param {Uint32Array} arr - array to copy\n* @returns {Uint32Array} new array\n*/\nfunction uint32array( arr ) {\n\treturn new Uint32Array( arr );\n}\n\n/**\n* Copies a `Float32Array`.\n*\n* @private\n* @param {Float32Array} arr - array to copy\n* @returns {Float32Array} new array\n*/\nfunction float32array( arr ) {\n\treturn new Float32Array( arr );\n}\n\n/**\n* Copies a `Float64Array`.\n*\n* @private\n* @param {Float64Array} arr - array to copy\n* @returns {Float64Array} new array\n*/\nfunction float64array( arr ) {\n\treturn new Float64Array( arr );\n}\n\n/**\n* Returns a hash of functions for copying typed arrays.\n*\n* @private\n* @returns {Object} function hash\n*/\nfunction typedarrays() {\n\tvar out = {\n\t\t'int8array': int8array,\n\t\t'uint8array': uint8array,\n\t\t'uint8clampedarray': uint8clampedarray,\n\t\t'int16array': int16array,\n\t\t'uint16array': uint16array,\n\t\t'int32array': int32array,\n\t\t'uint32array': uint32array,\n\t\t'float32array': float32array,\n\t\t'float64array': float64array\n\t};\n\treturn out;\n}\n\n\n// MAIN //\n\nhash = typedarrays();\n\n\n// EXPORTS //\n\nmodule.exports = hash;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar regexp = require( '@stdlib/utils-regexp-from-string' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar propertyNames = require( '@stdlib/utils-property-names' );\nvar propertyDescriptor = require( '@stdlib/utils-property-descriptor' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar defineProperty = require( '@stdlib/utils-define-property' );\nvar copyBuffer = require( '@stdlib/buffer-from-buffer' );\nvar typedArrays = require( './typed_arrays.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Clones a class instance.\n*\n* ## Notes\n*\n* - This should **only** be used for simple cases. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This approach should be considered **fragile**.\n* - The function is greedy, disregarding the notion of a `level`. Instead, the function deep copies all properties, as we assume the concept of `level` applies only to the class instance reference but not to its internal state. This prevents, in theory, two instances from sharing state.\n*\n*\n* @private\n* @param {Object} val - class instance\n* @returns {Object} new instance\n*/\nfunction cloneInstance( val ) {\n\tvar cache;\n\tvar names;\n\tvar name;\n\tvar refs;\n\tvar desc;\n\tvar tmp;\n\tvar ref;\n\tvar i;\n\n\tcache = [];\n\trefs = [];\n\n\tref = Object.create( getPrototypeOf( val ) );\n\tcache.push( val );\n\trefs.push( ref );\n\n\tnames = propertyNames( val );\n\tfor ( i = 0; i < names.length; i++ ) {\n\t\tname = names[ i ];\n\t\tdesc = propertyDescriptor( val, name );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( val[name] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( val[name], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( ref, name, desc );\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( ref );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( ref );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( ref );\n\t}\n\treturn ref;\n}\n\n/**\n* Copies an error object.\n*\n* @private\n* @param {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error - error to copy\n* @returns {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error copy\n*\n* @example\n* var err1 = new TypeError( 'beep' );\n*\n* var err2 = copyError( err1 );\n* // returns \n*/\nfunction copyError( error ) {\n\tvar cache = [];\n\tvar refs = [];\n\tvar keys;\n\tvar desc;\n\tvar tmp;\n\tvar key;\n\tvar err;\n\tvar i;\n\n\t// Create a new error...\n\terr = new error.constructor( error.message );\n\n\tcache.push( error );\n\trefs.push( err );\n\n\t// If a `stack` property is present, copy it over...\n\tif ( error.stack ) {\n\t\terr.stack = error.stack;\n\t}\n\t// Node.js specific (system errors)...\n\tif ( error.code ) {\n\t\terr.code = error.code;\n\t}\n\tif ( error.errno ) {\n\t\terr.errno = error.errno;\n\t}\n\tif ( error.syscall ) {\n\t\terr.syscall = error.syscall;\n\t}\n\t// Any enumerable properties...\n\tkeys = objectKeys( error );\n\tfor ( i = 0; i < keys.length; i++ ) {\n\t\tkey = keys[ i ];\n\t\tdesc = propertyDescriptor( error, key );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( error[ key ] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( error[ key ], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( err, key, desc );\n\t}\n\treturn err;\n}\n\n\n// MAIN //\n\n/**\n* Recursively performs a deep copy of an input object.\n*\n* @private\n* @param {*} val - value to copy\n* @param {(Array|Object)} copy - copy\n* @param {Array} cache - an array of visited objects\n* @param {Array} refs - an array of object references\n* @param {NonNegativeInteger} level - copy depth\n* @returns {*} deep copy\n*/\nfunction deepCopy( val, copy, cache, refs, level ) {\n\tvar parent;\n\tvar keys;\n\tvar name;\n\tvar desc;\n\tvar ctor;\n\tvar key;\n\tvar ref;\n\tvar x;\n\tvar i;\n\tvar j;\n\n\tlevel -= 1;\n\n\t// Primitives and functions...\n\tif (\n\t\ttypeof val !== 'object' ||\n\t\tval === null\n\t) {\n\t\treturn val;\n\t}\n\tif ( isBuffer( val ) ) {\n\t\treturn copyBuffer( val );\n\t}\n\tif ( isError( val ) ) {\n\t\treturn copyError( val );\n\t}\n\t// Objects...\n\tname = typeOf( val );\n\n\tif ( name === 'date' ) {\n\t\treturn new Date( +val );\n\t}\n\tif ( name === 'regexp' ) {\n\t\treturn regexp( val.toString() );\n\t}\n\tif ( name === 'set' ) {\n\t\treturn new Set( val );\n\t}\n\tif ( name === 'map' ) {\n\t\treturn new Map( val );\n\t}\n\tif (\n\t\tname === 'string' ||\n\t\tname === 'boolean' ||\n\t\tname === 'number'\n\t) {\n\t\t// If provided an `Object`, return an equivalent primitive!\n\t\treturn val.valueOf();\n\t}\n\tctor = typedArrays[ name ];\n\tif ( ctor ) {\n\t\treturn ctor( val );\n\t}\n\t// Class instances...\n\tif (\n\t\tname !== 'array' &&\n\t\tname !== 'object'\n\t) {\n\t\t// Cloning requires ES5 or higher...\n\t\tif ( typeof Object.freeze === 'function' ) {\n\t\t\treturn cloneInstance( val );\n\t\t}\n\t\treturn {};\n\t}\n\t// Arrays and plain objects...\n\tkeys = objectKeys( val );\n\tif ( level > 0 ) {\n\t\tparent = name;\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tx = val[ key ];\n\n\t\t\t// Primitive, Buffer, special class instance...\n\t\t\tname = typeOf( x );\n\t\t\tif (\n\t\t\t\ttypeof x !== 'object' ||\n\t\t\t\tx === null ||\n\t\t\t\t(\n\t\t\t\t\tname !== 'array' &&\n\t\t\t\t\tname !== 'object'\n\t\t\t\t) ||\n\t\t\t\tisBuffer( x )\n\t\t\t) {\n\t\t\t\tif ( parent === 'object' ) {\n\t\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\t\tdesc.value = deepCopy( x );\n\t\t\t\t\t}\n\t\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t\t} else {\n\t\t\t\t\tcopy[ key ] = deepCopy( x );\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Circular reference...\n\t\t\ti = indexOf( cache, x );\n\t\t\tif ( i !== -1 ) {\n\t\t\t\tcopy[ key ] = refs[ i ];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Plain array or object...\n\t\t\tref = ( isArray( x ) ) ? new Array( x.length ) : {};\n\t\t\tcache.push( x );\n\t\t\trefs.push( ref );\n\t\t\tif ( parent === 'array' ) {\n\t\t\t\tcopy[ key ] = deepCopy( x, ref, cache, refs, level );\n\t\t\t} else {\n\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\tdesc.value = deepCopy( x, ref, cache, refs, level );\n\t\t\t\t}\n\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t}\n\t\t}\n\t} else if ( name === 'array' ) {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tcopy[ key ] = val[ key ];\n\t\t}\n\t} else {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\tdefineProperty( copy, key, desc );\n\t\t}\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( copy );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( copy );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( copy );\n\t}\n\treturn copy;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepCopy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar deepCopy = require( './deep_copy.js' );\n\n\n// MAIN //\n\n/**\n* Copies or deep clones a value to an arbitrary depth.\n*\n* @param {*} value - value to copy\n* @param {NonNegativeInteger} [level=+infinity] - copy depth\n* @throws {TypeError} `level` must be a nonnegative integer\n* @returns {*} value copy\n*\n* @example\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\nfunction copy( value, level ) {\n\tvar out;\n\tif ( arguments.length > 1 ) {\n\t\tif ( !isNonNegativeInteger( level ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `level` must be a nonnegative integer. Value: `' + level + '`.' );\n\t\t}\n\t\tif ( level === 0 ) {\n\t\t\treturn value;\n\t\t}\n\t} else {\n\t\tlevel = PINF;\n\t}\n\tout = ( isArray( value ) ) ? new Array( value.length ) : {};\n\treturn deepCopy( value, out, [value], [out], level );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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* Copy or deep clone a value to an arbitrary depth.\n*\n* @module @stdlib/utils-copy\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ {'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\n\n// MODULES //\n\nvar copy = require( './copy.js' );\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an object; e.g., `{}`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an object\n*\n* @example\n* var bool = isObject( {} );\n* // returns true\n*\n* @example\n* var bool = isObject( null );\n* // returns false\n*/\nfunction isObject( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t!isArray( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObject;\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\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar objectPrototype = Object.prototype;\n\n\n// FUNCTIONS //\n\n/**\n* Tests that an object only has own properties.\n*\n* @private\n* @param {Object} obj - value to test\n* @returns {boolean} boolean indicating if an object only has own properties\n*/\nfunction ownProps( obj ) {\n\tvar key;\n\n\t// NOTE: possibility of perf boost if key enumeration order is known (see http://stackoverflow.com/questions/18531624/isplainobject-thing).\n\tfor ( key in obj ) {\n\t\tif ( !hasOwnProp( obj, key ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n\n// MAIN //\n\n/**\n* Tests if a value is a plain object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a plain object\n*\n* @example\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* @example\n* var bool = isPlainObject( null );\n* // returns false\n*/\nfunction isPlainObject( value ) {\n\tvar proto;\n\n\t// Screen for obvious non-objects...\n\tif ( !isObject( value ) ) {\n\t\treturn false;\n\t}\n\t// Objects with no prototype (e.g., `Object.create( null )`) are plain...\n\tproto = getPrototypeOf( value );\n\tif ( !proto ) {\n\t\treturn true;\n\t}\n\t// Objects having a prototype are plain if and only if they are constructed with a global `Object` function and the prototype points to the prototype of a plain object...\n\treturn (\n\t\t// Cannot have own `constructor` property:\n\t\t!hasOwnProp( value, 'constructor' ) &&\n\n\t\t// Prototype `constructor` property must be a function (see also https://bugs.jquery.com/ticket/9897 and http://stackoverflow.com/questions/18531624/isplainobject-thing):\n\t\thasOwnProp( proto, 'constructor' ) &&\n\t\tisFunction( proto.constructor ) &&\n\t\tnativeClass( proto.constructor ) === '[object Function]' &&\n\n\t\t// Test for object-specific method:\n\t\thasOwnProp( proto, 'isPrototypeOf' ) &&\n\t\tisFunction( proto.isPrototypeOf ) &&\n\n\t\t(\n\t\t\t// Test if the prototype matches the global `Object` prototype (same realm):\n\t\t\tproto === objectPrototype ||\n\n\t\t\t// Test that all properties are own properties (cross-realm; *most* likely a plain object):\n\t\t\townProps( value )\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - options to validate\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {(Error|null)} error object or null\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );\n\t}\n\tif ( hasOwnProp( options, 'url' ) ) {\n\t\topts.url = options.url;\n\t\tif ( !isString( opts.url ) ) {\n\t\t\treturn new TypeError( 'invalid option. `url` option must be a string primitive. Option: `' + opts.url + '`.' );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'message' ) ) {\n\t\topts.message = options.message;\n\t\tif ( !isString( opts.message ) ) {\n\t\t\treturn new TypeError( 'invalid option. `message` option must be a string primitive. Option: `' + opts.message + '`.' );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\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* Test if a value is a plain object.\n*\n* @module @stdlib/assert-is-plain-object\n*\n* @example\n* var isPlainObject = require( '@stdlib/assert-is-plain-object' );\n*\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* bool = isPlainObject( null );\n* // returns false\n*/\n\n// MODULES //\n\nvar isPlainObject = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar replace = require( '@stdlib/string-replace' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Returns a function which formats an error message for production.\n*\n* @param {Options} options - function options\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {Function} error formatting function\n*\n* @example\n* var opts = {\n* 'url': 'https://stdlib.io/error-decoder.html'\n* };\n*\n* var fcn = factory( opts );\n* // returns \n*/\nfunction factory( options ) {\n\tvar opts;\n\tvar err;\n\topts = copy( defaults );\n\terr = validate( opts, options );\n\tif ( err ) {\n\t\tthrow err;\n\t}\n\treturn formatProdErrorMessage;\n\n\t/**\n\t* Formats an error message for production.\n\t*\n\t* @private\n\t* @param {string} code - error code\n\t* @param {*} ...args - error message arguments\n\t* @returns {string} formatted error message\n\t*/\n\tfunction formatProdErrorMessage() {\n\t\tvar code = arguments[ 0 ];\n\t\tvar url = opts.url + '?code='+code;\n\t\tvar msg;\n\t\tvar i;\n\t\tfor ( i = 1; i < arguments.length; i++ ) {\n\t\t\turl += '&arg[]=' + encodeURIComponent( arguments[ i ] );\n\t\t}\n\t\tmsg = replace( opts.message, '{{url}}', url );\n\t\tmsg = replace( msg, '{{code}}', code );\n\t\treturn msg;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Format an error message for production.\n*\n* @module @stdlib/error-tools-fmtprodmsg\n*\n* @example\n* var formatProdErrorMessage = require( '@stdlib/error-tools-fmtprodmsg' );\n*\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar formatProdErrorMessage = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( formatProdErrorMessage, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @name formatProdErrorMessage\n* @type {Function}\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\nvar formatProdErrorMessage = factory( defaults );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["defineProperty","Object","has_define_property_support","err","builtin","objectProtoype","prototype","toStr","toString","defineGetter","__defineGetter__","defineSetter","__defineSetter__","lookupGetter","__lookupGetter__","lookupSetter","__lookupSetter__","polyfill","obj","prop","descriptor","hasValue","hasGet","hasSet","call","TypeError","__proto__","value","Error","get","set","require$$1","require$$2","lib","require$$0","main","configurable","enumerable","writable","primitive","FLG","Symbol","hasSymbols","toStringTag","tostring","native_class","v","has","hasOwnProperty","property","toStrTag","hasOwnProp","isOwn","tag","out","valueOf","String","nativeClass","test","object","isPrimitive","isObject","setReadOnly","isString","require$$3","RE_CHARS","str","s","i","length","replace","substring","re","Boolean","isBoolean","codegen","Function","self_1","self","window_1","window","global","module","exports","getThis","Self","Win","Global","arguments","root","nodeList","document","childNodes","typedarray","Int8Array","RE","check_1","reFunctionName","Array","isArray","isObjectLike","predicate","len","arrayfun","_isBuffer","constructor","isBuffer","REGEXP","match","name","ctor","slice","exec","ctorName","typeOf","type","toLowerCase","RegExp","rescape","isFunction","isRegExp","search","newval","Number","isNumber","POSITIVE_INFINITY","NEGATIVE_INFINITY","floor","Math","x","PINF","NINF","isInt","integer","isInteger","isNonNegativeInteger","getProto","getPrototypeOf","proto","reRegExp","isNan","isnan","isCollection","index_of","arr","searchElement","fromIndex","keys","has_arguments_bug","has_builtin","bool","isArguments","bool$8","detect","detect_1","native","propertyIsEnumerable","bool$7","isEnum","hasStringEnumBug","isEnumerableProperty","require$$4","builtin_wrapper","has_enumerable_prototype_bug","has_non_enumerable_properties_bug","is_constructor_prototype","w","indexOf","isConstructorPrototype","EXCLUDED_KEYS","win","bool$4","k","check","hasAutomationEqualityBug","HAS_WINDOW","HAS_ENUM_PROTO_BUG","HAS_NON_ENUM_PROPS_BUG","error","NON_ENUMERABLE","wrapper","skipConstructor","skipPrototype","isFcn","p","push","getOwnPropertyNames","propertyNames","getOwnPropertyDescriptor","propertyDescriptor","desc","Buffer","from","buffer","hasInt8Array","isInt8Array","GlobalInt8Array","INT8_MAX","hasUint8Array","Uint8Array","isUint8Array","GlobalUint8Array","UINT8_MAX","hasUint8ClampedArray","Uint8ClampedArray","isUint8ClampedArray","GlobalUint8ClampedArray","hasInt16Array","Int16Array","isInt16Array","GlobalInt16Array","INT16_MAX","hasUint16Array","Uint16Array","isUint16Array","GlobalUint16Array","UINT16_MAX","hasInt32Array","Int32Array","isInt32Array","GlobalInt32Array","INT32_MAX","hasUint32Array","Uint32Array","isUint32Array","GlobalUint32Array","UINT32_MAX","hasFloat32Array","Float32Array","isFloat32Array","GlobalFloat32Array","hasFloat64Array","Float64Array","isFloat64Array","GlobalFloat64Array","NaN","require$$5","require$$6","require$$7","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","isError","regexp","objectKeys","require$$8","require$$9","require$$10","require$$11","copyBuffer","require$$12","typedArrays","deepCopy","val","copy","cache","refs","level","parent","key","ref","j","tmp","message","stack","code","errno","syscall","copyError","Date","Set","Map","freeze","names","create","isExtensible","preventExtensions","isSealed","seal","isFrozen","cloneInstance","copy_1","objectPrototype","isPrototypeOf","ownProps","validate","opts","options","url","defaults","factory_1","msg","encodeURIComponent","formatProdErrorMessage","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","RangeError","format"],"mappings":";6kBAsBA,ICAIA,EDA0C,mBAA1BC,OAAOD,eAAkCC,OAAOD,eAAiB,KC4BrF,IAAAE,EAbA,WAEC,IAEC,OADAF,EAAgB,GAAI,IAAK,KAClB,EACN,MAAQG,GACT,OAAO,ICiBTC,EALqBH,OAAOD,eC/BxBK,EAAiBJ,OAAOK,UACxBC,EAAQF,EAAeG,SACvBC,EAAeJ,EAAeK,iBAC9BC,EAAeN,EAAeO,iBAC9BC,EAAeR,EAAeS,iBAC9BC,EAAeV,EAAeW,iBAuFlC,IAAAC,EAnDA,SAAyBC,EAAKC,EAAMC,GACnC,IAAId,EACAe,EACAC,EACAC,EAEJ,GAAoB,iBAARL,GAA4B,OAARA,GAAsC,mBAAtBX,EAAMiB,KAAMN,GAC3D,MAAM,IAAIO,UAAW,+DAAiEP,EAAM,MAE7F,GAA2B,iBAAfE,GAA0C,OAAfA,GAAoD,mBAA7Bb,EAAMiB,KAAMJ,GACzE,MAAM,IAAIK,UAAW,oEAAsEL,EAAa,MAyBzG,IAvBAC,EAAa,UAAWD,KAGtBP,EAAaW,KAAMN,EAAKC,IACxBJ,EAAaS,KAAMN,EAAKC,IAGxBb,EAAYY,EAAIQ,UAChBR,EAAIQ,UAAYrB,SAGTa,EAAKC,GACZD,EAAKC,GAASC,EAAWO,MAGzBT,EAAIQ,UAAYpB,GAEhBY,EAAKC,GAASC,EAAWO,OAG3BL,EAAW,QAASF,EACpBG,EAAW,QAASH,EAEfC,IAAcC,GAAUC,GAC5B,MAAM,IAAIK,MAAO,wHASlB,OANKN,GAAUb,GACdA,EAAae,KAAMN,EAAKC,EAAMC,EAAWS,KAErCN,GAAUZ,GACdA,EAAaa,KAAMN,EAAKC,EAAMC,EAAWU,KAEnCZ,GCrEJd,EAAU2B,EACVd,EAAWe,EAefC,EAjB+BC,IASb9B,EAEAa,EC7BdjB,EAAiBkC,EAmCrB,IAAAC,EAZA,SAAmCjB,EAAKC,EAAMQ,GAC7C3B,EAAgBkB,EAAKC,EAAM,CAC1BiB,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,KCJXM,EAL+BC,ECA/B,IAAAK,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCMjB,ICdIa,EDIJ,WACC,MACmB,mBAAXC,QACoB,iBAApBA,OAAQ,OCPPC,GAqBV,ICTAT,EDEA,WACC,OAASO,GAAqC,iBAAvBC,OAAOE,aEf/BC,EALY3C,OAAOK,UAAUE,SCAzBD,EAAQ2B,EAiCZ,IAAAW,EAPA,SAAsBC,GACrB,OAAOvC,EAAMiB,KAAMsB,IC3BhBC,EAAM9C,OAAOK,UAAU0C,eAyC3B,ICjBAf,EDIA,SAAqBN,EAAOsB,GAC3B,OACCtB,SAKMoB,EAAIvB,KAAMG,EAAOsB,IEnCrBC,EAA+B,mBAAXT,OAA0BA,OAAOE,YAAc,GCAnEQ,EAAajB,EACbS,EDIaO,ECHb3C,EAAQyB,EAwDZ,ICpCI5B,EAAU2B,EACVd,EDKJ,SAAsB6B,GACrB,IAAIM,EACAC,EACAC,EAEJ,GAAKR,QACJ,OAAOvC,EAAMiB,KAAMsB,GAEpBO,EAAMP,EAAGH,GACTS,EAAQD,EAAYL,EAAGH,GAGvB,IACCG,EAAGH,QAAgB,EAClB,MAAQxC,GACT,OAAOI,EAAMiB,KAAMsB,GASpB,OAPAQ,EAAM/C,EAAMiB,KAAMsB,GAEbM,EACJN,EAAGH,GAAgBU,SAEZP,EAAGH,GAEJW,GCdRrB,EAjBqBC,IASNjB,EAEAb,EChCXmD,ECDUC,OAAOlD,UAAUiD,QDyB/B,IEvBIE,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADA4B,EAAQ/B,KAAMG,IACP,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB6B,SAGjBhB,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,EAAW9B,EA0Bf,ICSI+B,EAAc5B,EACd6B,EDjBJ,SAAmBpC,GAClB,OAASiC,EAAajC,IAAWkC,EAAUlC,ICkBxCkC,EAAWG,EAKfF,EAAaC,EAAU,cANL/B,GAOlB8B,EAAaC,EAAU,WAAYF,GAKnC,IAAA5B,EAAiB8B,EClDbA,EAAW7B,EAAsC0B,YAKjDK,EAAW,yBAqDf,ICzCAhC,EDIA,SAAkBiC,GACjB,IACIC,EACAC,EAEJ,IAAML,EAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAGrG,GAAkB,MAAbA,EAAK,GAGT,IAAME,EADAF,EAAIG,OACI,EAAGD,GAAK,GACH,MAAbF,EAAKE,GADcA,KAO1B,YAAW,IAANA,GAAgBA,GAAK,EAClBF,EAAII,QAASL,EAAU,SAM/BE,GAHAA,EAAID,EAAIK,UAAW,EAAGH,IAGhBE,QAASL,EAAU,QAGzBC,EAAMA,EAAK,GAAMC,EAAID,EAAIK,UAAWH,KE/CrCI,EALS,ICyBT,IAAAjC,EAPA,SAAoBZ,GACnB,MAA0B,kBAAVA,GCjBbnB,ECDWiE,QAAQnE,UAAUE,SDyBjC,IEvBIiD,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADAnB,EAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAoBhC,GACnB,MAAsB,iBAAVA,IACNA,aAAiB8C,UAGjBjC,EACGkB,EAAM/B,GAEoB,qBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,GAAW9B,EAkCf,ICAI+B,GAAc5B,EACdwC,GDRJ,SAAoB/C,GACnB,OAASiC,EAAajC,IAAWkC,GAAUlC,ICSxCkC,GAAWG,EAKfF,GAAaY,GAAW,cANN1C,GAOlB8B,GAAaY,GAAW,WAAYb,IAKpC,IAAA5B,GAAiByC,GCpCjB,IAAAC,GAPA,WACC,OAAO,IAAIC,SAAU,eAAd,ICFRC,GAL4B,iBAATC,KAAsBA,KAAO,KCKhDC,GAL8B,iBAAXC,OAAwBA,OAAS,6GCAhD9D,GAA0B,iBAAX+D,GAAwBA,GAAS,KAKpDC,OAAOC,QAAUjE,OCLbwD,GAAYxC,GAAuC0B,YACnDwB,GAAUrD,GACVsD,GAAOrD,GACPsD,GAAMtB,GACNuB,sCAkDJ,IAAApD,GA7BA,SAAoBwC,GACnB,GAAKa,UAAUnB,OAAS,CACvB,IAAMK,GAAWC,GAChB,MAAM,IAAIlD,UAAW,+DAA+DkD,EAAQ,MAE7F,GAAKA,EACJ,OAAOS,KAKT,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,MAAM,IAAI3D,MAAO,uDC3Cd6D,GCOYvD,KDNZwD,GAAWD,GAAKE,UAAYF,GAAKE,SAASC,WER1CC,GAAaC,UCEbC,GAAK7D,EACLwD,GHUaA,GGTbG,GDCaA,GC6BjB,IAAAG,GAnBA,WACC,MAEe,mBAAPD,IAGe,iBAAfF,IAGa,mBAAbH,ICST,IAAAvD,GAPA,WACC,MAAO,2BCEJ8D,GAAiBlE,GADHG,EAOL+D,GAAgB,SCjCR/D,MDsCrB,IAAAD,GAAiBgE,GEtCbxC,GAAcvB,EAwClB,ICpBAD,GDWKiE,MAAMC,QACND,MAAMC,QARX,SAAkBxE,GACjB,MAAkC,mBAAzB8B,GAAa9B,IEzBnBwE,GAAUjE,GC0Bd,ICGIkE,GDbJ,SAAuBzE,GACtB,OACW,OAAVA,GACiB,iBAAVA,GCQSO,EAOLkE,GAAc,oBFR3B,SAAmBC,GAClB,GAA0B,mBAAdA,EACX,MAAM,IAAI5E,UAAW,sDAAwD4E,EAAY,MAE1F,OASA,SAAgB1E,GACf,IAAI2E,EACAlC,EACJ,IAAM+B,GAASxE,GACd,OAAO,EAGR,GAAa,KADb2E,EAAM3E,EAAM0C,QAEX,OAAO,EAER,IAAMD,EAAI,EAAGA,EAAIkC,EAAKlC,IACrB,IAAiC,IAA5BiC,EAAW1E,EAAOyC,IACtB,OAAO,EAGT,OAAO,GEpBuCmC,CAAUH,KAK1D,IAAAnE,GAAiBmE,GCvCbA,GAAelE,GA+CnB,IC3BAD,GDOA,SAAmBN,GAClB,OACCyE,GAAczE,KAGbA,EAAM6E,WAEL7E,EAAM8E,aAGgC,mBAA/B9E,EAAM8E,YAAYC,UACzB/E,EAAM8E,YAAYC,SAAU/E,KEtC5B8B,GAAcvB,EACd6D,GAAKhE,GAA0C4E,OAC/CD,GAAW1E,GAuDf,IAAAG,GAxBA,SAA0BW,GACzB,IAAI8D,EACAC,EACAC,EAEJ,IAAe,YADfD,EAAOpD,GAAaX,GAAIiE,MAAO,GAAI,KACC,UAATF,IAAqB/D,EAAE2D,YAAc,CAE/D,GAA0B,iBAD1BK,EAAOhE,EAAE2D,aACQI,KAChB,OAAOC,EAAKD,KAGb,GADAD,EAAQb,GAAGiB,KAAMF,EAAKtG,YAErB,OAAOoG,EAAO,GAGhB,OAAKF,GAAU5D,GACP,SAED+D,GCnDJI,GCkBkB/E,GDmCtB,IErDI+E,GDkBkB/E,GCAtB,ICFIgF,GHkBJ,SAAiBpE,GAChB,IAAIqE,EAGJ,OAAW,OAANrE,EACG,OAKM,YAHdqE,SAAcrE,GAINmE,GAAUnE,GAAIsE,cAEfD,GG9BJlG,GDNJ,SAAiB6B,GAChB,OAAOmE,GAAUnE,GAAIsE,eCetBnF,GAZkBC,KAOajB,GAAWiG,GCtBtCA,GAAShF,GA2Bb,ICNAD,GDFA,SAAqBN,GAEpB,MAA6B,aAApBuF,GAAQvF,IErBdqF,GCFOK,OAAO/G,UAAU0G,KD0B5B,IEvBIvD,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADAqF,GAAKxF,KAAMG,IACJ,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBN,IA0CrB,IC1CIoF,GAAUpF,EACVqF,GAAaxF,GACbgC,GAAW/B,EAAsC4B,YACjD4D,GDuBJ,SAAmB7F,GAClB,MAAsB,iBAAVA,IACNA,aAAiB0F,SAGjB7E,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MC2BxB,ICvCAM,GDmBA,SAAkBiC,EAAKuD,EAAQC,GAC9B,IAAM3D,GAAUG,GACf,MAAM,IAAIzC,UAAW,wEAA0EyC,EAAM,MAEtG,GAAKH,GAAU0D,GACdA,EAASH,GAASG,GAClBA,EAAS,IAAIJ,OAAQI,EAAQ,UAEzB,IAAMD,GAAUC,GACpB,MAAM,IAAIhG,UAAW,+FAAiGgG,EAAS,MAEhI,IAAM1D,GAAU2D,KAAaH,GAAYG,GACxC,MAAM,IAAIjG,UAAW,gGAAkGiG,EAAS,MAEjI,OAAOxD,EAAII,QAASmD,EAAQC,IEhC7B,IAAAnF,GAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCAjBM,GCjBiB0F,OCAbnH,GCAS0B,GAMS5B,UAAUE,SDkBhC,IEvBIiD,GAAc1B,EACd4F,GAAS3F,GACT0B,GFSJ,SAAe/B,GACd,IAEC,OADAnB,GAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IETLqC,GARiBN,IA2CrB,IAAAyB,GAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiBgG,KAGjBnF,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MCnCpBiC,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd0F,GDfJ,SAAmBjG,GAClB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa8D,GAAU,cANL5F,IAOlB8B,GAAa8D,GAAU,WAAY/D,IAKnC,IAAA5B,GAAiB2F,GCvBjB3F,GALmB0F,OAAOE,kBCS1B5F,GA1BaC,GAqBa4F,kBChCtBC,GCsBQC,KAAKD,MDIjB,IENA9F,GFDA,SAAoBgG,GACnB,OAAQF,GAAME,KAAOA,GGpBlBC,GAAOhG,GACPiG,GAAOpG,GACPqG,GAAQpG,GAuBZ,IAAAqG,GAXA,SAAoB1G,GACnB,OACCA,EAAQuG,IACRvG,EAAQwG,IACRC,GAAOzG,IClBLiG,GAAW1F,GAAsC0B,YACjDwE,GAAQrG,GA6BZ,IAAAQ,GAVA,SAAoBZ,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,ICvBLiG,GAAW1F,GAAsC2B,SACjDuE,GAAQrG,GA6BZ,IAAA4B,GAVA,SAAoBhC,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICMI+B,GAAc5B,EACdoG,GDdJ,SAAoB3G,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICexCkC,GAAWG,GAKfF,GAAawE,GAAW,cANNtG,IAOlB8B,GAAawE,GAAW,WAAYzE,IAKpC,IAAA5B,GAAiBqG,GCvDbA,GAAYpG,GAAuC0B,YA6BvD,IAAArB,GAVA,SAA+BZ,GAC9B,OACC2G,GAAW3G,IACXA,GAAS,GCtBP2G,GAAYpG,GAAuC2B,SA6BvD,IAAAF,GAVA,SAA+BhC,GAC9B,OACC2G,GAAW3G,IACXA,EAAM4B,WAAa,GCtBjBK,GAAc1B,GACd2B,GAAW9B,GAsCf,ICGI+B,GAAc5B,EACdqG,GDXJ,SAA+B5G,GAC9B,OAASiC,GAAajC,IAAWkC,GAAUlC,ICYxCkC,GAAWG,GAKfF,GAAayE,GAAsB,cANjBvG,IAOlB8B,GAAayE,GAAsB,WAAY1E,IAK/C,IAAA5B,GAAiBsG,GCxDbC,GAAWvI,OAAOwI,eCatB,IAAAC,GARA,SAAmBxH,GAElB,OAAOA,EAAIQ,WCPR+B,GAAcvB,EACdsG,GAAWzG,GA+Bf,IAAAd,GAnBA,SAAyBC,GACxB,IAAIwH,EAAQF,GAAUtH,GACtB,OAAKwH,GAAmB,OAAVA,EACNA,EAEgC,sBAAnCjF,GAAavC,EAAIuF,aAEdvF,EAAIuF,YAAYnG,UAEnBY,aAAejB,OACZA,OAAOK,UAGR,MCzBJF,GHIaoI,GGHbvH,GAAWe,GCFXwG,GDAatG,GAQAjC,OAAOwI,gBACZrI,GAEAa,GCoBZ,ICdAgB,GDFA,SAAyBN,GACxB,OACCA,QAGO,MAGRA,EAAQ1B,OAAQ0B,GAET6G,GAAU7G,KEzBd8G,GAAiBvG,GACjBuB,GAAc1B,EAwClB,ICrBAE,GDAA,SAAkBN,GACjB,GAAsB,iBAAVA,GAAgC,OAAVA,EACjC,OAAO,EAGR,GAAKA,aAAiBC,MACrB,OAAO,EAGR,KAAQD,GAAQ,CACf,GAA8B,mBAAzB8B,GAAa9B,GACjB,OAAO,EAERA,EAAQ8G,GAAgB9G,GAEzB,OAAO,GEdR,IAAAQ,GAPA,WACC,MAAO,oCCWJwG,GAAW5G,GADGG,EAOLyG,GAAU,SChCRzG,UCAX6B,GAAW7B,EAAsC0B,YACjD+E,GFyCaA,GEXjB,ICdA1G,GDAA,SAAuBiC,GACtB,IAAMH,GAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAMrG,OAHAA,EAAMyE,KAAW3B,KAAM9C,IAGN,IAAImD,OAAQnD,EAAI,GAAIA,EAAI,IAAO,MEJjD,IAAA/B,GAPA,SAAgB8F,GACf,OAASA,GAAMA,GCfZL,GAAW1F,GAAsC0B,YACjDgF,GCcQ1G,GDmBZ,IAAAK,GAVA,SAAgBZ,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,IE3BLiG,GAAW1F,GAAsC2B,SACjD+E,GDcQ1G,GCeZ,IAAAyB,GAVA,SAAgBhC,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd2G,GDfJ,SAAgBlH,GACf,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa+E,GAAO,cANF7G,IAOlB8B,GAAa+E,GAAO,WAAYhF,IAKhC,IAAA5B,GAAiB4G,GCxDbP,GAAYpG,GAkChB,IClCI2G,GAAQ3G,GACR4G,GDmBJ,SAAuBnH,GACtB,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QENqB,kBDnBzBN,GAAW/B,EAAsC4B,YACjD0E,GAAYtE,GAAuCJ,YA0GvD,IAAAmF,GAhDA,SAAkBC,EAAKC,EAAeC,GACrC,IAAI5C,EACAlC,EACJ,IAAM0E,GAAcE,KAAUjF,GAAUiF,GACvC,MAAM,IAAIvH,UAAW,0EAA4EuH,EAAM,MAGxG,GAAa,KADb1C,EAAM0C,EAAI3E,QAET,OAAQ,EAET,GAA0B,IAArBmB,UAAUnB,OAAe,CAC7B,IAAMiE,GAAWY,GAChB,MAAM,IAAIzH,UAAW,6DAA+DyH,EAAY,MAEjG,GAAKA,GAAa,EAAI,CACrB,GAAKA,GAAa5C,EACjB,OAAQ,EAETlC,EAAI8E,OAEJ9E,EAAIkC,EAAM4C,GACD,IACR9E,EAAI,QAINA,EAAI,EAGL,GAAKyE,GAAOI,IACX,KAAQ7E,EAAIkC,EAAKlC,IAChB,GAAKyE,GAAOG,EAAI5E,IACf,OAAOA,OAIT,KAAQA,EAAIkC,EAAKlC,IAChB,GAAK4E,EAAK5E,KAAQ6E,EACjB,OAAO7E,EAIV,OAAQ,GErDTnC,GALcC,GClBd,IAAA9B,GAPA,SAAeuB,GACd,OAAO1B,OAAOkJ,KAAMlJ,OAAQ0B,KCrBzBwH,GAAOjH,GAmCX,IAAAkH,GAPA,WACC,OAlBD,WACC,OAA8C,KAArCD,GAAM3D,YAAe,IAAKnB,OAiB5BX,CAAM,EAAG,ICxBjB2F,QALoC,IAAhBpJ,OAAOkJ,KCAvB1F,GAAcvB,EA+BlB,IC1BIoH,GD0BJnH,GAPA,SAAsBR,GACrB,MAAkC,uBAAzB8B,GAAa9B,ICzBnB4H,GAAcrH,GA2BdsH,GAPJ,WACC,OAAOD,GAAa/D,WAMdiE,GAKP,IC3BIH,GD2BJI,GAAiBJ,GEDjBK,GAL2B1J,OAAOK,UAAUsJ,qBDHxCC,IAvBS3H,GAiBGV,KAAM,OAAQ,KAW9B,IE5BIuC,GAAW7B,EACX2G,GAAQ9G,GAAmC6B,YAC3C0E,GAAYtG,GAAuC4B,YACnDkG,GAAS9F,GACT+F,GFwBaT,GE6BjB,IAAAnH,GAzBA,SAA+BR,EAAOsB,GACrC,IAAIqG,EACJ,OACC3H,YAKD2H,EAAOQ,GAAOtI,KAAMG,EAAOsB,KACb8G,IAAoBhG,GAAUpC,IAIzCkH,GAFF5F,GAAYA,IAGXqF,GAAWrF,IACXA,GAAY,GACZA,EAAWtB,EAAM0C,OAGZiF,IC3BRrH,GAL2BC,GCnBvBiB,GAAajB,EACb8H,GAAuBjI,GACvBoE,GAAUnE,GACVsG,GAAYtE,GCiChB,IAAA/B,GAjBwBC,GACbH,GDQX,SAAsBJ,GACrB,OACW,OAAVA,GACiB,iBAAVA,IACNwE,GAASxE,IACc,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QAhCS4F,YAiCf9G,GAAYxB,EAAO,YAClBqI,GAAsBrI,EAAO,WEtC5B4H,GAAcrH,GACd9B,GAAU2B,GAKVgF,GAAQb,MAAM5F,UAAUyG,MA+B5B,IAAAmD,GAVA,SAAevI,GACd,OAAK4H,GAAa5H,GACVvB,GAAS2G,GAAMvF,KAAMG,IAEtBvB,GAASuB,ICnBjB,ICAAwI,GAZ2BjI,IDK3B,cCEuC,aCWvCkI,IAlB2BlI,GAKjB,CACT1B,SAAY,MAO0B,YCCvC,ICJI8I,GDIJe,GAPA,SAAiC1I,GAChC,OAASA,EAAM8E,aAAe9E,EAAM8E,YAAYnG,YAAcqB,GER3D2I,GAAwB,oBAAXtF,YAA2B,EAASA,ODAjD7B,GAAajB,EACbqI,GAAUxI,GACVmF,GAASlF,GACTwI,GAAyBxG,GACzByG,wPACAC,GCAaJ,GD2CbK,GAzBJ,WACC,IAAIC,EACJ,GAAuB,cAAlB1D,GAAQwD,IACZ,OAAO,EAER,IAAME,KAAKF,GACV,KAEmC,IAAjCH,GAASE,GAAeG,IACxBzH,GAAYuH,GAAKE,IACJ,OAAbF,GAAKE,IACkB,WAAvB1D,GAAQwD,GAAKE,KAEbJ,GAAwBE,GAAKE,IAE7B,MAAQzK,GACT,OAAO,EAGT,OAAO,EAMD0K,GAKP,IErDIvB,GAA2B,oBAAXtE,OCAhB8F,GHqDaxB,GGpDbkB,GAAyBzI,GACzBgJ,GDGazB,GCuBjB,IC5BIlD,GAAelE,GACfiB,GAAapB,EACbwH,GAAcvH,GACdgJ,GAAqBhH,GACrBiH,GAAyBhB,GACzBO,GDSJ,SAAkB7I,GACjB,IAAoB,IAAfoJ,KAAyBD,GAC7B,OAAON,GAAwB7I,GAEhC,IACC,OAAO6I,GAAwB7I,GAC9B,MAAQuJ,GACT,OAAO,ICfLC,iHAyEJ,IC7EI/K,GAAU4B,GACVoJ,GAAUpH,GACV/C,GDuBJ,SAAeU,GACd,IAAI0J,EACAC,EACAC,EACAjI,EACAsH,EACAY,EACApH,EAGJ,GADAd,EAAM,GACDiG,GAAa5H,GAAU,CAE3B,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,YAGb,OAAO8C,EAER,GAAsB,iBAAV3B,GAEX,GAAKA,EAAM0C,OAAS,IAAMlB,GAAYxB,EAAO,KAC5C,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,gBAGR,CAEN,IAAe,KADf+K,EAA2B,mBAAV5J,KACQyE,GAAczE,GACtC,OAAO2B,EAERgI,EAAkBN,IAAsBO,EAEzC,IAAMX,KAAKjJ,EACF2J,GAAuB,cAANV,IAAuBzH,GAAYxB,EAAOiJ,IAClEtH,EAAImI,KAAMjI,OAAQoH,IAGpB,GAAKK,GAEJ,IADAI,EAAkBb,GAAwB7I,GACpCyC,EAAI,EAAGA,EAAI+G,GAAe9G,OAAQD,IACvCoH,EAAIL,GAAgB/G,GACZiH,GAAyB,gBAANG,IAAyBrI,GAAYxB,EAAO6J,IACtElI,EAAImI,KAAMjI,OAAQgI,IAIrB,OAAOlI,GEnDRrB,GDrBkBF,GADIG,KA6BbkJ,GAEAhL,GAGDa,GE7BRoI,QALmD,IAA/BpJ,OAAOyL,oBCAvBC,GAAgB1L,OAAOyL,oBAgC3B,IChCIvC,GAAOjH,GCgCX,IAAAD,GAjBkBC,GFUlB,SAA8BP,GAC7B,OAAOgK,GAAe1L,OAAQ0B,KCA/B,SAA8BA,GAC7B,OAAOwH,GAAMlJ,OAAQ0B,KEtBtB0H,QALwD,IAApCpJ,OAAO2L,yBCAvBC,GAAqB5L,OAAO2L,yBAuChC,ICvCIzI,GAAajB,ECkCjB,IAAAD,GAjBkBC,GFUlB,SAAmCP,EAAOsB,GACzC,IAAI6I,EACJ,OAAKnK,cAIa,KADlBmK,EAAOD,GAAoBlK,EAAOsB,IAF1B,KAG4B6I,GCLrC,SAAmCnK,EAAOsB,GACzC,OAAKE,GAAYxB,EAAOsB,GAChB,CACNb,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,EAAOsB,IAGX,iyqBEvBR,ICDId,uJCb2B4J,ODc3B9K,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GAjB2BC,KASnBC,GAEAlB,GEjBJqI,GANapH,GACJH,GAKiBiK,MCN1BtF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAI,GAVA,SAAqB8J,GACpB,IAAMvF,GAAUuF,GACf,MAAM,IAAIxK,UAAW,oDAAsDwK,EAAS,KAErF,OAAOF,GAAOC,KAAMC,IC1BjBvF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAd,GAVA,SAAqBgL,GACpB,IAAMvF,GAAUuF,GACf,MAAM,IAAIxK,UAAW,oDAAsDwK,EAAS,KAErF,OAAO,IAAIF,GAAQE,ICOpBhK,GHtBiBqH,GGMNvH,GACIC,GClBXyB,GAAcvB,EAKdgK,GAAsC,mBAAdpG,UA6B5B,IClCI3D,GAA8B,mBAAd2D,UAA6BA,UAAY,KCAzDqG,GFwBJ,SAAsBxK,GACrB,OACGuK,IAAgBvK,aAAiBmE,WACV,uBAAzBrC,GAAa9B,IExBXyK,GDEajK,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAgC,mBAApBoD,GACX,OAAO,EAGR,IACCpD,EAAM,IAAIoD,GAAiB,CAAE,EAAG,MAAO,KAAMC,MAC7C/C,EACC6C,GAAanD,IACA,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEO,MDDZA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb8B,mBAAd0F,UAA6BA,eAAY,EDczD7E,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB0BC,KFSlB9B,GAEAa,GGvBJwC,GAAcvB,EAKdoK,GAAwC,mBAAfC,WA6B7B,IClCIpK,GAA+B,mBAAfoK,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuB7K,GACtB,OACG2K,IAAiB3K,aAAiB4K,YACX,wBAAzB9I,GAAa9B,IEzBX8K,GDGatK,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArByD,GACX,OAAO,EAGR,IAECzD,EAAM,IAAIyD,GADVzD,EAAM,CAAE,EAAG,MAAO,KAAM0D,IAAaA,MAErCpD,EACCkD,GAAcxD,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ0D,MAAb1D,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCb+B,mBAAfmM,WAA8BA,gBAAa,EDc3DtL,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdyK,GAAsD,mBAAtBC,kBA6BpC,IClCIzK,GAAsC,mBAAtByK,kBAAqCA,kBAAoB,KCAzEC,GFwBJ,SAA8BlL,GAC7B,OACGgL,IAAwBhL,aAAiBiL,mBAClB,+BAAzBnJ,GAAa9B,IE1BXmL,GDIa3K,GCuCjB,IAAAA,GA7BA,WACC,IAAImH,EACAN,EAEJ,GAAwC,mBAA5B8D,GACX,OAAO,EAGR,IACC9D,EAAM,IAAI8D,GAAyB,EAAG,EAAG,EAAG,EAAG,KAAM,KAAM,IAAK,MAChExD,EACCuD,GAAqB7D,IACR,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,MAAbA,EAAK,IACQ,MAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbsC,mBAAtBwM,kBAAqCA,uBAAoB,EDczE3L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjBkCC,KFS1B9B,GAEAa,GGvBJwC,GAAcvB,EAKd6K,GAAwC,mBAAfC,WA6B7B,IClCI7K,GAA+B,mBAAf6K,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBtL,GACtB,OACGoL,IAAiBpL,aAAiBqL,YACX,wBAAzBvJ,GAAa9B,IExBXuL,GDEa/K,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArBkE,GACX,OAAO,EAGR,IACClE,EAAM,IAAIkE,GAAkB,CAAE,EAAG,MAAO,KAAMC,QAC9C7D,EACC2D,GAAcjE,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,QDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAf4M,WAA8BA,gBAAa,EDc3D/L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdkL,GAA0C,mBAAhBC,YA6B9B,IClCIlL,GAAgC,mBAAhBkL,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwB3L,GACvB,OACGyL,IAAkBzL,aAAiB0L,aACZ,yBAAzB5J,GAAa9B,IEzBX4L,GDGapL,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBuE,GACX,OAAO,EAGR,IAECvE,EAAM,IAAIuE,GADVvE,EAAM,CAAE,EAAG,MAAO,KAAMwE,MAAcA,QAEtClE,EACCgE,GAAetE,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQwE,QAAbxE,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhBiN,YAA+BA,iBAAc,EDc7DpM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKduL,GAAwC,mBAAfC,WA6B7B,IClCIvL,GAA+B,mBAAfuL,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBhM,GACtB,OACG8L,IAAiB9L,aAAiB+L,YACX,wBAAzBjK,GAAa9B,IExBXiM,GDEazL,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB4E,GACX,OAAO,EAGR,IACC5E,EAAM,IAAI4E,GAAkB,CAAE,EAAG,MAAO,KAAMC,aAC9CvE,EACCqE,GAAc3E,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,aDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAfsN,WAA8BA,gBAAa,EDc3DzM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd4L,GAA0C,mBAAhBC,YA6B9B,IClCI5L,GAAgC,mBAAhB4L,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwBrM,GACvB,OACGmM,IAAkBnM,aAAiBoM,aACZ,yBAAzBtK,GAAa9B,IEzBXsM,GDGa9L,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBiF,GACX,OAAO,EAGR,IAECjF,EAAM,IAAIiF,GADVjF,EAAM,CAAE,EAAG,MAAO,KAAMkF,WAAcA,aAEtC5E,EACC0E,GAAehF,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQkF,aAAblF,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhB2N,YAA+BA,iBAAc,EDc7D9M,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdiM,GAA4C,mBAAjBC,aA6B/B,IClCIjM,GAAiC,mBAAjBiM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB1M,GACxB,OACGwM,IAAmBxM,aAAiByM,cACb,0BAAzB3K,GAAa9B,IE1BXuG,GAAOnG,GACPuM,GDGanM,GCqCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvBsF,GACX,OAAO,EAGR,IACCtF,EAAM,IAAIsF,GAAoB,CAAE,EAAK,MAAO,KAAM,OAClDhF,EACC+E,GAAgBrF,IACH,IAAbA,EAAK,IACQ,oBAAbA,EAAK,KACS,oBAAdA,EAAK,IACLA,EAAK,KAAQd,GAEb,MAAQ/H,GACTmJ,GAAO,EAER,OAAOA,GCtBR,ICDIlJ,GCbiC,mBAAjBgO,aAAgCA,kBAAe,EDc/DnN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB6BC,KFSrB9B,GAEAa,GGvBJwC,GAAcvB,EAKdqM,GAA4C,mBAAjBC,aA6B/B,IClCIrM,GAAiC,mBAAjBqM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB9M,GACxB,OACG4M,IAAmB5M,aAAiB6M,cACb,0BAAzB/K,GAAa9B,IE1BX+M,GDIavM,GCoCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvB0F,GACX,OAAO,EAGR,IACC1F,EAAM,IAAI0F,GAAoB,CAAE,EAAK,MAAO,KAAMC,MAClDrF,EACCmF,GAAgBzF,IACH,IAAbA,EAAK,IACQ,OAAbA,EAAK,KACS,OAAdA,EAAK,IACLA,EAAK,IAAQA,EAAK,GAElB,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCrBR,ICKIxC,GANA1G,GCbiC,mBAAjBoO,aAAgCA,kBAAe,EDc/DvN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCajBkF,GET4B5E,KFSrB9B,GAEAa,GAMR,IG7BI6E,GAAY5D,GACZqK,GAAaxK,GACb6K,GAAoB5K,GACpBgL,GAAahJ,GACbqJ,GAAcpD,GACdyD,GAAakB,GACbb,GAAcc,GACdT,GAAeU,GACfN,GHqBa1H,GGJjB,SAASiI,GAAW/F,GACnB,OAAO,IAAIlD,GAAWkD,GAUvB,SAASgG,GAAYhG,GACpB,OAAO,IAAIuD,GAAYvD,GAUxB,SAASiG,GAAmBjG,GAC3B,OAAO,IAAI4D,GAAmB5D,GAU/B,SAASkG,GAAYlG,GACpB,OAAO,IAAIgE,GAAYhE,GAUxB,SAASmG,GAAanG,GACrB,OAAO,IAAIqE,GAAarE,GAUzB,SAASoG,GAAYpG,GACpB,OAAO,IAAI0E,GAAY1E,GAUxB,SAASqG,GAAarG,GACrB,OAAO,IAAI+E,GAAa/E,GAUzB,SAASsG,GAActG,GACtB,OAAO,IAAIoF,GAAcpF,GAU1B,SAASuG,GAAcvG,GACtB,OAAO,IAAIwF,GAAcxF,GAgC1B,IClJI7F,GAAajB,EACbiE,GAAUpE,GACV2E,GAAW1E,GACXwN,GAAUxL,GACVkD,GAAS+C,GACTwF,GAASb,GACTrE,GAAUsE,GACVa,GAAaZ,GACbnD,GAAgBgE,GAChB9D,GAAqB+D,GACrBnH,GAAiBoH,GACjB7P,GAAiB8P,EACjBC,GAAaC,GACbC,GD+GO,CACTlB,UAAaA,GACbC,WAAcA,GACdC,kBAAqBA,GACrBC,WAAcA,GACdC,YAAeA,GACfC,WAAcA,GACdC,YAAeA,GACfC,aAAgBA,GAChBC,aAAgBA,ICQlB,SAASW,GAAUC,EAAKC,EAAMC,EAAOC,EAAMC,GAC1C,IAAIC,EACArH,EACAtC,EACAiF,EACAhF,EACA2J,EACAC,EACAzI,EACA7D,EACAuM,EAKJ,GAHAJ,GAAS,EAIO,iBAARJ,GACC,OAARA,EAEA,OAAOA,EAER,GAAKzJ,GAAUyJ,GACd,OAAOJ,GAAYI,GAEpB,GAAKX,GAASW,GACb,OAnFF,SAAoBjF,GACnB,IAEI/B,EACA2C,EACA8E,EACAH,EACAtQ,EACAiE,EAPAiM,EAAQ,GACRC,EAAO,GA8BX,IArBAnQ,EAAM,IAAI+K,EAAMzE,YAAayE,EAAM2F,SAEnCR,EAAM5E,KAAMP,GACZoF,EAAK7E,KAAMtL,GAGN+K,EAAM4F,QACV3Q,EAAI2Q,MAAQ5F,EAAM4F,OAGd5F,EAAM6F,OACV5Q,EAAI4Q,KAAO7F,EAAM6F,MAEb7F,EAAM8F,QACV7Q,EAAI6Q,MAAQ9F,EAAM8F,OAEd9F,EAAM+F,UACV9Q,EAAI8Q,QAAU/F,EAAM+F,SAGrB9H,EAAOuG,GAAYxE,GACb9G,EAAI,EAAGA,EAAI+E,EAAK9E,OAAQD,IAC7BqM,EAAMtH,EAAM/E,GACZ0H,EAAOD,GAAoBX,EAAOuF,GAC7BtN,GAAY2I,EAAM,WACtB8E,EAAQzK,GAAS+E,EAAOuF,IAAY,GAAK,GACzC3E,EAAKnK,MAAQuO,GAAUhF,EAAOuF,GAAOG,EAAKP,EAAOC,GAAO,IAEzDtQ,GAAgBG,EAAKsQ,EAAK3E,GAE3B,OAAO3L,EA0CC+Q,CAAWf,GAKnB,GAAc,UAFdtJ,EAAOK,GAAQiJ,IAGd,OAAO,IAAIgB,MAAOhB,GAEnB,GAAc,WAATtJ,EACJ,OAAO4I,GAAQU,EAAI3P,YAEpB,GAAc,QAATqG,EACJ,OAAO,IAAIuK,IAAKjB,GAEjB,GAAc,QAATtJ,EACJ,OAAO,IAAIwK,IAAKlB,GAEjB,GACU,WAATtJ,GACS,YAATA,GACS,WAATA,EAGA,OAAOsJ,EAAI5M,UAGZ,GADAuD,EAAOmJ,GAAapJ,GAEnB,OAAOC,EAAMqJ,GAGd,GACU,UAATtJ,GACS,WAATA,EAGA,MAA8B,mBAAlB5G,OAAOqR,OA1KrB,SAAwBnB,GACvB,IAAIE,EACAkB,EACA1K,EACAyJ,EACAxE,EACA8E,EACAF,EACAtM,EAUJ,IARAiM,EAAQ,GACRC,EAAO,GAEPI,EAAMzQ,OAAOuR,OAAQ/I,GAAgB0H,IACrCE,EAAM5E,KAAM0E,GACZG,EAAK7E,KAAMiF,GAEXa,EAAQ5F,GAAewE,GACjB/L,EAAI,EAAGA,EAAImN,EAAMlN,OAAQD,IAC9ByC,EAAO0K,EAAOnN,GACd0H,EAAOD,GAAoBsE,EAAKtJ,GAC3B1D,GAAY2I,EAAM,WACtB8E,EAAQzK,GAASgK,EAAItJ,IAAY,GAAK,GACtCiF,EAAKnK,MAAQuO,GAAUC,EAAItJ,GAAO+J,EAAKP,EAAOC,GAAO,IAEtDtQ,GAAgB0Q,EAAK7J,EAAMiF,GAW5B,OATM7L,OAAOwR,aAActB,IAC1BlQ,OAAOyR,kBAAmBhB,GAEtBzQ,OAAO0R,SAAUxB,IACrBlQ,OAAO2R,KAAMlB,GAETzQ,OAAO4R,SAAU1B,IACrBlQ,OAAOqR,OAAQZ,GAETA,EAuIEoB,CAAe3B,GAEhB,GAIR,GADAhH,EAAOuG,GAAYS,GACdI,EAAQ,EAEZ,IADAC,EAAS3J,EACH8J,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAE7B1I,EAAIkI,EADJM,EAAMtH,EAAMwH,IAIZ9J,EAAOK,GAAQe,GAED,iBAANA,GACD,OAANA,GAEU,UAATpB,GACS,WAATA,GAEDH,GAAUuB,GAEM,WAAXuI,GACJ1E,EAAOD,GAAoBsE,EAAKM,GAC3BtN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQuO,GAAUjI,IAExBjI,GAAgBoQ,EAAMK,EAAK3E,IAE3BsE,EAAMK,GAAQP,GAAUjI,IAMd,KADZ7D,EAAImG,GAAS8F,EAAOpI,KAMpByI,EAAQvK,GAAS8B,GAAQ,IAAI/B,MAAO+B,EAAE5D,QAAW,GACjDgM,EAAM5E,KAAMxD,GACZqI,EAAK7E,KAAMiF,GACK,UAAXF,EACJJ,EAAMK,GAAQP,GAAUjI,EAAGyI,EAAKL,EAAOC,EAAMC,IAE7CzE,EAAOD,GAAoBsE,EAAKM,GAC3BtN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQuO,GAAUjI,EAAGyI,EAAKL,EAAOC,EAAMC,IAE7CvQ,GAAgBoQ,EAAMK,EAAK3E,KAd3BsE,EAAMK,GAAQH,EAAMlM,QAiBhB,GAAc,UAATyC,EACX,IAAM8J,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAE7BP,EADAK,EAAMtH,EAAMwH,IACER,EAAKM,QAGpB,IAAME,EAAI,EAAGA,EAAIxH,EAAK9E,OAAQsM,IAC7BF,EAAMtH,EAAMwH,GACZ7E,EAAOD,GAAoBsE,EAAKM,GAChCzQ,GAAgBoQ,EAAMK,EAAK3E,GAY7B,OATM7L,OAAOwR,aAActB,IAC1BlQ,OAAOyR,kBAAmBtB,GAEtBnQ,OAAO0R,SAAUxB,IACrBlQ,OAAO2R,KAAMxB,GAETnQ,OAAO4R,SAAU1B,IACrBlQ,OAAOqR,OAAQlB,GAETA,EAMR,IC3RIjK,GAAUjE,GACVqG,GAAuBxG,GAAmD6B,YAC1EsE,GAAOlG,GACPkO,GDwRaA,GCtOjB,IAAA6B,GAnBA,SAAepQ,EAAO4O,GACrB,IAAIjN,EACJ,GAAKkC,UAAUnB,OAAS,EAAI,CAC3B,IAAMkE,GAAsBgI,GAC3B,MAAM,IAAI9O,UAAW,oEAAsE8O,EAAQ,MAEpG,GAAe,IAAVA,EACJ,OAAO5O,OAGR4O,EAAQrI,GAGT,OADA5E,EAAQ6C,GAASxE,GAAY,IAAIuE,MAAOvE,EAAM0C,QAAW,GAClD6L,GAAUvO,EAAO2B,EAAK,CAAC3B,GAAQ,CAAC2B,GAAMiN,ICd9CtO,GALWC,GC5BPiE,GAAUjE,GA8Bd,IC9BI2B,GDmBJ,SAAmBlC,GAClB,MACkB,iBAAVA,GACG,OAAVA,IACCwE,GAASxE,ICtBR4F,GAAaxF,GACb0G,GAAiBzG,GACjBmB,GAAaa,EACbP,GAAcwG,EAKd+H,GAAkB/R,OAAOK,UAgF7B,IAAA6B,GAvCA,SAAwBR,GACvB,IAAI+G,EAGJ,QAAM7E,GAAUlC,OAIhB+G,EAAQD,GAAgB9G,MAOtBwB,GAAYxB,EAAO,gBAGpBwB,GAAYuF,EAAO,gBACnBnB,GAAYmB,EAAMjC,cACmB,sBAArChD,GAAaiF,EAAMjC,cAGnBtD,GAAYuF,EAAO,kBACnBnB,GAAYmB,EAAMuJ,iBAIjBvJ,IAAUsJ,IAzDb,SAAmB9Q,GAClB,IAAIuP,EAGJ,IAAMA,KAAOvP,EACZ,IAAMiC,GAAYjC,EAAKuP,GACtB,OAAO,EAGT,OAAO,EAmDLyB,CAAUvQ,MCjFTkC,GCegB3B,GDdhBiB,GAAapB,EACbgC,GAAW/B,EAAsC4B,YAqCrD,wJEvCIU,GAAUpC,GACVkO,GAAOrO,GACPoQ,GFeJ,SAAmBC,EAAMC,GACxB,OAAMxO,GAAUwO,GAGXlP,GAAYkP,EAAS,SACzBD,EAAKE,IAAMD,EAAQC,KACbvO,GAAUqO,EAAKE,MACb,IAAI7Q,UAAW,qEAAuE2Q,EAAKE,IAAM,MAGrGnP,GAAYkP,EAAS,aACzBD,EAAKvB,QAAUwB,EAAQxB,SACjB9M,GAAUqO,EAAKvB,UACb,IAAIpP,UAAW,yEAA2E2Q,EAAKvB,QAAU,MAG3G,KAdC,IAAIpP,UAAW,iEAAmE4Q,EAAU,OEhBjGE,GAAWvO,GAwDf,IAAAwO,GAnCA,SAAkBH,GACjB,IAAID,EACAjS,EAGJ,GAFAiS,EAAOhC,GAAMmC,IACbpS,EAAMgS,GAAUC,EAAMC,GAErB,MAAMlS,EAEP,OAUA,WACC,IAEIsS,EACArO,EAHA2M,EAAOvL,UAAW,GAClB8M,EAAMF,EAAKE,IAAM,SAASvB,EAG9B,IAAM3M,EAAI,EAAGA,EAAIoB,UAAUnB,OAAQD,IAClCkO,GAAO,UAAYI,mBAAoBlN,UAAWpB,IAInD,OAFAqO,EAAMnO,GAAS8N,EAAKvB,QAAS,UAAWyB,GACxCG,EAAMnO,GAASmO,EAAK,WAAY1B,KCtC9B4B,GCbUzQ,GACCH,IDWGG,EAOLyQ,GAAwB,UALvB3Q,IAUd,IAAAC,GAAiB0Q,UEiFjB,WACC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjP,EACAwM,EACAvM,EASJ,IANAwO,EAAUpN,UAAW,GACrBqN,EAASrN,UAAW,GAGpBsN,GADAG,EAAQzN,UAAW,GADnBwN,GAHAD,EAAQvN,UAAW,IAGLnB,UAECA,OACf8O,EAAMN,EACAzO,EAAI,EAAGA,EAAI4O,EAAO5O,IAAM,CAI7B,GAHAgP,EAAIL,EAAO3O,GACXuM,EAAInL,UAAWpB,EAAE,GAEH,WADd8O,EAAOD,EAAO7O,EAAE0O,IAEVnC,EAAI,EACRA,EAAI,EACOA,GAAKyC,IAChBzC,EAAIyC,EAAI,QAEH,GAAc,SAATF,EACNvC,EAAI,GACRA,GAAKyC,GACI,GAEG,KADXzC,GAAKyC,KAEJzC,GAAKyC,GAGIzC,GAAKyC,IAChBzC,GAAKyC,IACKA,IACTzC,GAAKyC,QAGD,GAAKzC,EAAI,GAAKA,GAAKyC,EACzB,MAAM,IAAIC,WAAYC,GAAQ,+FAAgGlP,EAAGuM,KAElIxM,EAAIyO,EAASxO,IAGJ,GAAgB,IAAXyO,EACbM,GAAOxC,EAAIxM,EAEXgP,GAAOxC,EAAIxM,EAGb,OAAOgP"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 4d9b415..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).sub2ind=r()}(this,(function(){"use strict";function t(t){var r=t.default;if("function"==typeof r){var e=function(){return r.apply(this,arguments)};e.prototype=r.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(t).forEach((function(r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})})),e}var r="function"==typeof Object.defineProperty?Object.defineProperty:null;var e=function(){try{return r({},"x",{}),!0}catch(t){return!1}},n=Object.defineProperty,o=Object.prototype,i=o.toString,u=o.__defineGetter__,a=o.__defineSetter__,f=o.__lookupGetter__,c=o.__lookupSetter__;var s=function(t,r,e){var n,s,l,h;if("object"!=typeof t||null===t||"[object Array]"===i.call(t))throw new TypeError("invalid argument. First argument must be an object. Value: `"+t+"`.");if("object"!=typeof e||null===e||"[object Array]"===i.call(e))throw new TypeError("invalid argument. Property descriptor must be an object. Value: `"+e+"`.");if((s="value"in e)&&(f.call(t,r)||c.call(t,r)?(n=t.__proto__,t.__proto__=o,delete t[r],t[r]=e.value,t.__proto__=n):t[r]=e.value),l="get"in e,h="set"in e,s&&(l||h))throw new Error("invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.");return l&&u&&u.call(t,r,e.get),h&&a&&a.call(t,r,e.set),t},l=n,h=s,p=e()?l:h,y=p;var v=function(t,r,e){y(t,r,{configurable:!1,enumerable:!1,writable:!1,value:e})},g=v;var w=function(t){return"string"==typeof t};var d=function(){return"function"==typeof Symbol&&"symbol"==typeof Symbol("foo")}();var b=function(){return d&&"symbol"==typeof Symbol.toStringTag},m=Object.prototype.toString,A=m;var E=function(t){return A.call(t)},_=Object.prototype.hasOwnProperty;var O=function(t,r){return null!=t&&_.call(t,r)},P="function"==typeof Symbol?Symbol.toStringTag:"",j=O,R=P,T=m;var U=E,S=function(t){var r,e,n;if(null==t)return T.call(t);e=t[R],r=j(t,R);try{t[R]=void 0}catch(r){return T.call(t)}return n=T.call(t),r?t[R]=e:delete t[R],n},I=b()?S:U,B=String.prototype.valueOf;var Y=I,x=function(t){try{return B.call(t),!0}catch(t){return!1}},C=b();var M=function(t){return"object"==typeof t&&(t instanceof String||(C?x(t):"[object String]"===Y(t)))},L=w,F=M;var D=g,N=function(t){return L(t)||F(t)},k=M;D(N,"isPrimitive",w),D(N,"isObject",k);var V=N,z=V.isPrimitive,G=/[-\/\\^$*+?.()|[\]{}]/g;var X=function(t){var r,e;if(!z(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");if("/"===t[0])for(e=t.length-1;e>=0&&"/"!==t[e];e--);return void 0===e||e<=0?t.replace(G,"\\$&"):(r=(r=t.substring(1,e)).replace(G,"\\$&"),t=t[0]+r+t.substring(e))},$=/./;var H=function(t){return"boolean"==typeof t},W=Boolean.prototype.toString;var q=I,J=function(t){try{return W.call(t),!0}catch(t){return!1}},Z=b();var K=function(t){return"object"==typeof t&&(t instanceof Boolean||(Z?J(t):"[object Boolean]"===q(t)))},Q=H,tt=K;var rt=g,et=function(t){return Q(t)||tt(t)},nt=K;rt(et,"isPrimitive",H),rt(et,"isObject",nt);var ot=et;var it=function(){return new Function("return this;")()},ut="object"==typeof self?self:null,at="object"==typeof window?window:null,ft="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},ct="object"==typeof ft?ft:null;module.exports=ct;var st=ot.isPrimitive,lt=it,ht=ut,pt=at,yt=t(Object.freeze({__proto__:null}));var vt=function(t){if(arguments.length){if(!st(t))throw new TypeError("invalid argument. Must provide a boolean primitive. Value: `"+t+"`.");if(t)return lt()}if(ht)return ht;if(pt)return pt;if(yt)return yt;throw new Error("unexpected error. Unable to resolve global object.")},gt=vt(),wt=gt.document&>.document.childNodes,dt=Int8Array,bt=$,mt=wt,At=dt;var Et=function(){return"function"==typeof bt||"object"==typeof At||"function"==typeof mt};var _t=function(){return/^\s*function\s*([^(]*)/i},Ot=_t;g(Ot,"REGEXP",_t());var Pt=Ot,jt=I;var Rt=Array.isArray?Array.isArray:function(t){return"[object Array]"===jt(t)},Tt=Rt;var Ut=function(t){return null!==t&&"object"==typeof t};g(Ut,"isObjectLikeArray",function(t){if("function"!=typeof t)throw new TypeError("invalid argument. Must provide a function. Value: `"+t+"`.");return function(r){var e,n;if(!Tt(r))return!1;if(0===(e=r.length))return!1;for(n=0;ndr&&br(t)},Ar=hr.isPrimitive,Er=mr;var _r=function(t){return Ar(t)&&Er(t)},Or=hr.isObject,Pr=mr;var jr=function(t){return Or(t)&&Pr(t.valueOf())},Rr=_r,Tr=jr;var Ur=g,Sr=function(t){return Rr(t)||Tr(t)},Ir=jr;Ur(Sr,"isPrimitive",_r),Ur(Sr,"isObject",Ir);var Br=Sr,Yr=Br.isPrimitive;var xr=function(t){return Yr(t)&&t>=0},Cr=Br.isObject;var Mr=function(t){return Cr(t)&&t.valueOf()>=0},Lr=xr,Fr=Mr;var Dr=g,Nr=function(t){return Lr(t)||Fr(t)},kr=Mr;Dr(Nr,"isPrimitive",xr),Dr(Nr,"isObject",kr);var Vr=Nr,zr=Object.getPrototypeOf;var Gr=function(t){return t.__proto__},Xr=I,$r=Gr;var Hr=function(t){var r=$r(t);return r||null===r?r:"[object Function]"===Xr(t.constructor)?t.constructor.prototype:t instanceof Object?Object.prototype:null},Wr=zr,qr=Hr,Jr=zt(Object.getPrototypeOf)?Wr:qr;var Zr=function(t){return null==t?null:(t=Object(t),Jr(t))},Kr=Zr,Qr=I;var te=function(t){if("object"!=typeof t||null===t)return!1;if(t instanceof Error)return!0;for(;t;){if("[object Error]"===Qr(t))return!0;t=Kr(t)}return!1};var re=function(){return/^\/((?:\\\/|[^\/])+)\/([imgy]*)$/},ee=re;g(ee,"REGEXP",re());var ne=V.isPrimitive,oe=ee;var ie=function(t){if(!ne(t))throw new TypeError("invalid argument. Must provide a regular expression string. Value: `"+t+"`.");return(t=oe().exec(t))?new RegExp(t[1],t[2]):null};var ue=function(t){return t!=t},ae=hr.isPrimitive,fe=ue;var ce=function(t){return ae(t)&&fe(t)},se=hr.isObject,le=ue;var he=function(t){return se(t)&&le(t.valueOf())},pe=ce,ye=he;var ve=g,ge=function(t){return pe(t)||ye(t)},we=he;ve(ge,"isPrimitive",ce),ve(ge,"isObject",we);var de=ge,be=gr;var me=de,Ae=function(t){return"object"==typeof t&&null!==t&&"number"==typeof t.length&&be(t.length)&&t.length>=0&&t.length<=9007199254740991},Ee=V.isPrimitive,_e=Br.isPrimitive;var Oe=function(t,r,e){var n,o;if(!Ae(t)&&!Ee(t))throw new TypeError("invalid argument. First argument must be an array-like object. Value: `"+t+"`.");if(0===(n=t.length))return-1;if(3===arguments.length){if(!_e(e))throw new TypeError("invalid argument. `fromIndex` must be an integer. Value: `"+e+"`.");if(e>=0){if(e>=n)return-1;o=e}else(o=n+e)<0&&(o=0)}else o=0;if(me(r)){for(;o=0&&r=0&&t.length<=4294967295&&Ge(t,"callee")&&!Xe(t,"callee")},qe=We,Je=je,Ze=Array.prototype.slice;var Ke=function(t){return qe(t)?Je(Ze.call(t)):Je(t)};var Qe=ze((function(){}),"prototype"),tn=!ze({toString:null},"toString");var rn,en=function(t){return t.constructor&&t.constructor.prototype===t},nn="undefined"==typeof window?void 0:window,on=O,un=Pe,an=kt,fn=en,cn=["console","external","frame","frameElement","frames","innerHeight","innerWidth","outerHeight","outerWidth","pageXOffset","pageYOffset","parent","scrollLeft","scrollTop","scrollX","scrollY","self","webkitIndexedDB","webkitStorageInfo","window"],sn=nn;rn=function(){var t;if("undefined"===an(sn))return!1;for(t in sn)try{-1===un(cn,t)&&on(sn,t)&&null!==sn[t]&&"object"===an(sn[t])&&fn(sn[t])}catch(t){return!0}return!1}();var ln="undefined"!=typeof window,hn=rn,pn=en,yn=ln;var vn=St,gn=O,wn=We,dn=Qe,bn=tn,mn=function(t){if(!1===yn&&!hn)return pn(t);try{return pn(t)}catch(t){return!1}},An=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"];var En=je,_n=Ke,On=function(t){var r,e,n,o,i,u,a;if(o=[],wn(t)){for(a=0;a0&&!gn(t,"0"))for(a=0;a>18&63]+xn[o>>12&63]+xn[o>>6&63]+xn[63&o]);return i.join("")}function Nn(t){var r;Ln||Fn();for(var e=t.length,n=e%3,o="",i=[],u=16383,a=0,f=e-n;af?f:a+u));return 1===n?(r=t[e-1],o+=xn[r>>2],o+=xn[r<<4&63],o+="=="):2===n&&(r=(t[e-2]<<8)+t[e-1],o+=xn[r>>10],o+=xn[r>>4&63],o+=xn[r<<2&63],o+="="),i.push(o),i.join("")}function kn(t,r,e,n,o){var i,u,a=8*o-n-1,f=(1<>1,s=-7,l=e?o-1:0,h=e?-1:1,p=t[r+l];for(l+=h,i=p&(1<<-s)-1,p>>=-s,s+=a;s>0;i=256*i+t[r+l],l+=h,s-=8);for(u=i&(1<<-s)-1,i>>=-s,s+=n;s>0;u=256*u+t[r+l],l+=h,s-=8);if(0===i)i=1-c;else{if(i===f)return u?NaN:1/0*(p?-1:1);u+=Math.pow(2,n),i-=c}return(p?-1:1)*u*Math.pow(2,i-n)}function Vn(t,r,e,n,o,i){var u,a,f,c=8*i-o-1,s=(1<>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,y=n?1:-1,v=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,u=s):(u=Math.floor(Math.log(r)/Math.LN2),r*(f=Math.pow(2,-u))<1&&(u--,f*=2),(r+=u+l>=1?h/f:h*Math.pow(2,1-l))*f>=2&&(u++,f/=2),u+l>=s?(a=0,u=s):u+l>=1?(a=(r*f-1)*Math.pow(2,o),u+=l):(a=r*Math.pow(2,l-1)*Math.pow(2,o),u=0));o>=8;t[e+p]=255&a,p+=y,a/=256,o-=8);for(u=u<0;t[e+p]=255&u,p+=y,u/=256,c-=8);t[e+p-y]|=128*v}var zn={}.toString,Gn=Array.isArray||function(t){return"[object Array]"==zn.call(t)};Wn.TYPED_ARRAY_SUPPORT=void 0===ft.TYPED_ARRAY_SUPPORT||ft.TYPED_ARRAY_SUPPORT;var Xn=$n();function $n(){return Wn.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Hn(t,r){if($n()=$n())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+$n().toString(16)+" bytes");return 0|t}function to(t){return!(null==t||!t._isBuffer)}function ro(t,r){if(to(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return Uo(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return So(t).length;default:if(n)return Uo(t).length;r=(""+r).toLowerCase(),n=!0}}function eo(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return wo(this,r,e);case"utf8":case"utf-8":return po(this,r,e);case"ascii":return vo(this,r,e);case"latin1":case"binary":return go(this,r,e);case"base64":return ho(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return bo(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function no(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function oo(t,r,e,n,o){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0){if(!o)return-1;e=0}if("string"==typeof r&&(r=Wn.from(r,n)),to(r))return 0===r.length?-1:io(t,r,e,n,o);if("number"==typeof r)return r&=255,Wn.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):io(t,[r],e,n,o);throw new TypeError("val must be string, number or Buffer")}function io(t,r,e,n,o){var i,u=1,a=t.length,f=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,a/=2,f/=2,e/=2}function c(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(o){var s=-1;for(i=e;ia&&(e=a-f),i=e;i>=0;i--){for(var l=!0,h=0;ho&&(n=o):n=o;var i=r.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var u=0;u>8,o=e%256,i.push(o),i.push(n);return i}(r,t.length-e),t,e,n)}function ho(t,r,e){return 0===r&&e===t.length?Nn(t):Nn(t.slice(r,e))}function po(t,r,e){e=Math.min(t.length,e);for(var n=[],o=r;o239?4:c>223?3:c>191?2:1;if(o+l<=e)switch(l){case 1:c<128&&(s=c);break;case 2:128==(192&(i=t[o+1]))&&(f=(31&c)<<6|63&i)>127&&(s=f);break;case 3:i=t[o+1],u=t[o+2],128==(192&i)&&128==(192&u)&&(f=(15&c)<<12|(63&i)<<6|63&u)>2047&&(f<55296||f>57343)&&(s=f);break;case 4:i=t[o+1],u=t[o+2],a=t[o+3],128==(192&i)&&128==(192&u)&&128==(192&a)&&(f=(15&c)<<18|(63&i)<<12|(63&u)<<6|63&a)>65535&&f<1114112&&(s=f)}null===s?(s=65533,l=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=l}return function(t){var r=t.length;if(r<=yo)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),""},Wn.prototype.compare=function(t,r,e,n,o){if(!to(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),r<0||e>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&r>=e)return 0;if(n>=o)return-1;if(r>=e)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),a=Math.min(i,u),f=this.slice(n,o),c=t.slice(r,e),s=0;so)&&(e=o),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return uo(this,t,r,e);case"utf8":case"utf-8":return ao(this,t,r,e);case"ascii":return fo(this,t,r,e);case"latin1":case"binary":return co(this,t,r,e);case"base64":return so(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return lo(this,t,r,e);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},Wn.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var yo=4096;function vo(t,r,e){var n="";e=Math.min(t.length,e);for(var o=r;on)&&(e=n);for(var o="",i=r;ie)throw new RangeError("Trying to access beyond buffer length")}function Ao(t,r,e,n,o,i){if(!to(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>o||rt.length)throw new RangeError("Index out of range")}function Eo(t,r,e,n){r<0&&(r=65535+r+1);for(var o=0,i=Math.min(t.length-e,2);o>>8*(n?o:1-o)}function _o(t,r,e,n){r<0&&(r=4294967295+r+1);for(var o=0,i=Math.min(t.length-e,4);o>>8*(n?o:3-o)&255}function Oo(t,r,e,n,o,i){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function Po(t,r,e,n,o){return o||Oo(t,0,e,4),Vn(t,r,e,n,23,4),e+4}function jo(t,r,e,n,o){return o||Oo(t,0,e,8),Vn(t,r,e,n,52,8),e+8}Wn.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(o*=256);)n+=this[t+--r]*o;return n},Wn.prototype.readUInt8=function(t,r){return r||mo(t,1,this.length),this[t]},Wn.prototype.readUInt16LE=function(t,r){return r||mo(t,2,this.length),this[t]|this[t+1]<<8},Wn.prototype.readUInt16BE=function(t,r){return r||mo(t,2,this.length),this[t]<<8|this[t+1]},Wn.prototype.readUInt32LE=function(t,r){return r||mo(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},Wn.prototype.readUInt32BE=function(t,r){return r||mo(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},Wn.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||mo(t,r,this.length);for(var n=this[t],o=1,i=0;++i=(o*=128)&&(n-=Math.pow(2,8*r)),n},Wn.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||mo(t,r,this.length);for(var n=r,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*r)),i},Wn.prototype.readInt8=function(t,r){return r||mo(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},Wn.prototype.readInt16LE=function(t,r){r||mo(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},Wn.prototype.readInt16BE=function(t,r){r||mo(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},Wn.prototype.readInt32LE=function(t,r){return r||mo(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},Wn.prototype.readInt32BE=function(t,r){return r||mo(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},Wn.prototype.readFloatLE=function(t,r){return r||mo(t,4,this.length),kn(this,t,!0,23,4)},Wn.prototype.readFloatBE=function(t,r){return r||mo(t,4,this.length),kn(this,t,!1,23,4)},Wn.prototype.readDoubleLE=function(t,r){return r||mo(t,8,this.length),kn(this,t,!0,52,8)},Wn.prototype.readDoubleBE=function(t,r){return r||mo(t,8,this.length),kn(this,t,!1,52,8)},Wn.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||Ao(this,t,r,e,Math.pow(2,8*e)-1,0);var o=1,i=0;for(this[r]=255&t;++i=0&&(i*=256);)this[r+o]=t/i&255;return r+e},Wn.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,1,255,0),Wn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},Wn.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,65535,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):Eo(this,t,r,!0),r+2},Wn.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,65535,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):Eo(this,t,r,!1),r+2},Wn.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,4294967295,0),Wn.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):_o(this,t,r,!0),r+4},Wn.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,4294967295,0),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):_o(this,t,r,!1),r+4},Wn.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Ao(this,t,r,e,o-1,-o)}var i=0,u=1,a=0;for(this[r]=255&t;++i>0)-a&255;return r+e},Wn.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var o=Math.pow(2,8*e-1);Ao(this,t,r,e,o-1,-o)}var i=e-1,u=1,a=0;for(this[r+i]=255&t;--i>=0&&(u*=256);)t<0&&0===a&&0!==this[r+i+1]&&(a=1),this[r+i]=(t/u>>0)-a&255;return r+e},Wn.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,1,127,-128),Wn.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},Wn.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,32767,-32768),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):Eo(this,t,r,!0),r+2},Wn.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,2,32767,-32768),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):Eo(this,t,r,!1),r+2},Wn.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,2147483647,-2147483648),Wn.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):_o(this,t,r,!0),r+4},Wn.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||Ao(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),Wn.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):_o(this,t,r,!1),r+4},Wn.prototype.writeFloatLE=function(t,r,e){return Po(this,t,r,!0,e)},Wn.prototype.writeFloatBE=function(t,r,e){return Po(this,t,r,!1,e)},Wn.prototype.writeDoubleLE=function(t,r,e){return jo(this,t,r,!0,e)},Wn.prototype.writeDoubleBE=function(t,r,e){return jo(this,t,r,!1,e)},Wn.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--o)t[o+r]=this[o+e];else if(i<1e3||!Wn.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(i=r;i55295&&e<57344){if(!o){if(e>56319){(r-=3)>-1&&i.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&i.push(239,191,189);continue}o=e;continue}if(e<56320){(r-=3)>-1&&i.push(239,191,189),o=e;continue}e=65536+(o-55296<<10|e-56320)}else o&&(r-=3)>-1&&i.push(239,191,189);if(o=null,e<128){if((r-=1)<0)break;i.push(e)}else if(e<2048){if((r-=2)<0)break;i.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;i.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;i.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return i}function So(t){return function(t){var r,e,n,o,i,u;Ln||Fn();var a=t.length;if(a%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[a-2]?2:"="===t[a-1]?1:0,u=new Mn(3*a/4-i),n=i>0?a-4:a;var f=0;for(r=0,e=0;r>16&255,u[f++]=o>>8&255,u[f++]=255&o;return 2===i?(o=Cn[t.charCodeAt(r)]<<2|Cn[t.charCodeAt(r+1)]>>4,u[f++]=255&o):1===i&&(o=Cn[t.charCodeAt(r)]<<10|Cn[t.charCodeAt(r+1)]<<4|Cn[t.charCodeAt(r+2)]>>2,u[f++]=o>>8&255,u[f++]=255&o),u}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Ro,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Io(t,r,e,n){for(var o=0;o=r.length||o>=t.length);++o)r[o+e]=t[o];return o}function Bo(t){return null!=t&&(!!t._isBuffer||Yo(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&Yo(t.slice(0,0))}(t))}function Yo(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var xo=Object.freeze({__proto__:null,Buffer:Wn,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),Wn.alloc(+t)},isBuffer:Bo,kMaxLength:Xn}),Co=Wn;module.exports=Co;var Mo=Bt,Lo=t(Object.freeze({__proto__:null}));var Fo=function(){var t,r;if("function"!=typeof Lo)return!1;try{r="function"==typeof Lo.from?Lo.from([1,2,3,4]):new Lo([1,2,3,4]),t=Mo(r)&&1===r[0]&&2===r[1]&&3===r[2]&&4===r[3]}catch(r){t=!1}return t},Do=Fo;var No=t(xo).Buffer,ko=function(){throw new Error("not implemented")},Vo=Do()?No:ko,zo=zt(Vo.from),Go=Bt,Xo=Vo;var $o=function(t){if(!Go(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return Xo.from(t)},Ho=Bt,Wo=Vo;var qo=function(t){if(!Ho(t))throw new TypeError("invalid argument. Must provide a Buffer. Value: `"+t+"`");return new Wo(t)},Jo=zo?$o:qo,Zo=I,Ko="function"==typeof Int8Array;var Qo="function"==typeof Int8Array?Int8Array:null,ti=function(t){return Ko&&t instanceof Int8Array||"[object Int8Array]"===Zo(t)},ri=Qo;var ei=function(){var t,r;if("function"!=typeof ri)return!1;try{r=new ri([1,3.14,-3.14,128]),t=ti(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-128===r[3]}catch(r){t=!1}return t};var ni="function"==typeof Int8Array?Int8Array:void 0,oi=function(){throw new Error("not implemented")},ii=ei()?ni:oi,ui=I,ai="function"==typeof Uint8Array;var fi="function"==typeof Uint8Array?Uint8Array:null,ci=function(t){return ai&&t instanceof Uint8Array||"[object Uint8Array]"===ui(t)},si=fi;var li=function(){var t,r;if("function"!=typeof si)return!1;try{r=new si(r=[1,3.14,-3.14,256,257]),t=ci(r)&&1===r[0]&&3===r[1]&&253===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var hi="function"==typeof Uint8Array?Uint8Array:void 0,pi=function(){throw new Error("not implemented")},yi=li()?hi:pi,vi=I,gi="function"==typeof Uint8ClampedArray;var wi="function"==typeof Uint8ClampedArray?Uint8ClampedArray:null,di=function(t){return gi&&t instanceof Uint8ClampedArray||"[object Uint8ClampedArray]"===vi(t)},bi=wi;var mi=function(){var t,r;if("function"!=typeof bi)return!1;try{r=new bi([-1,0,1,3.14,4.99,255,256]),t=di(r)&&0===r[0]&&0===r[1]&&1===r[2]&&3===r[3]&&5===r[4]&&255===r[5]&&255===r[6]}catch(r){t=!1}return t};var Ai="function"==typeof Uint8ClampedArray?Uint8ClampedArray:void 0,Ei=function(){throw new Error("not implemented")},_i=mi()?Ai:Ei,Oi=I,Pi="function"==typeof Int16Array;var ji="function"==typeof Int16Array?Int16Array:null,Ri=function(t){return Pi&&t instanceof Int16Array||"[object Int16Array]"===Oi(t)},Ti=ji;var Ui=function(){var t,r;if("function"!=typeof Ti)return!1;try{r=new Ti([1,3.14,-3.14,32768]),t=Ri(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-32768===r[3]}catch(r){t=!1}return t};var Si="function"==typeof Int16Array?Int16Array:void 0,Ii=function(){throw new Error("not implemented")},Bi=Ui()?Si:Ii,Yi=I,xi="function"==typeof Uint16Array;var Ci="function"==typeof Uint16Array?Uint16Array:null,Mi=function(t){return xi&&t instanceof Uint16Array||"[object Uint16Array]"===Yi(t)},Li=Ci;var Fi=function(){var t,r;if("function"!=typeof Li)return!1;try{r=new Li(r=[1,3.14,-3.14,65536,65537]),t=Mi(r)&&1===r[0]&&3===r[1]&&65533===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var Di="function"==typeof Uint16Array?Uint16Array:void 0,Ni=function(){throw new Error("not implemented")},ki=Fi()?Di:Ni,Vi=I,zi="function"==typeof Int32Array;var Gi="function"==typeof Int32Array?Int32Array:null,Xi=function(t){return zi&&t instanceof Int32Array||"[object Int32Array]"===Vi(t)},$i=Gi;var Hi=function(){var t,r;if("function"!=typeof $i)return!1;try{r=new $i([1,3.14,-3.14,2147483648]),t=Xi(r)&&1===r[0]&&3===r[1]&&-3===r[2]&&-2147483648===r[3]}catch(r){t=!1}return t};var Wi="function"==typeof Int32Array?Int32Array:void 0,qi=function(){throw new Error("not implemented")},Ji=Hi()?Wi:qi,Zi=I,Ki="function"==typeof Uint32Array;var Qi="function"==typeof Uint32Array?Uint32Array:null,tu=function(t){return Ki&&t instanceof Uint32Array||"[object Uint32Array]"===Zi(t)},ru=Qi;var eu=function(){var t,r;if("function"!=typeof ru)return!1;try{r=new ru(r=[1,3.14,-3.14,4294967296,4294967297]),t=tu(r)&&1===r[0]&&3===r[1]&&4294967293===r[2]&&0===r[3]&&1===r[4]}catch(r){t=!1}return t};var nu="function"==typeof Uint32Array?Uint32Array:void 0,ou=function(){throw new Error("not implemented")},iu=eu()?nu:ou,uu=I,au="function"==typeof Float32Array;var fu="function"==typeof Float32Array?Float32Array:null,cu=function(t){return au&&t instanceof Float32Array||"[object Float32Array]"===uu(t)},su=pr,lu=fu;var hu=function(){var t,r;if("function"!=typeof lu)return!1;try{r=new lu([1,3.14,-3.14,5e40]),t=cu(r)&&1===r[0]&&3.140000104904175===r[1]&&-3.140000104904175===r[2]&&r[3]===su}catch(r){t=!1}return t};var pu="function"==typeof Float32Array?Float32Array:void 0,yu=function(){throw new Error("not implemented")},vu=hu()?pu:yu,gu=I,wu="function"==typeof Float64Array;var du="function"==typeof Float64Array?Float64Array:null,bu=function(t){return wu&&t instanceof Float64Array||"[object Float64Array]"===gu(t)},mu=du;var Au=function(){var t,r;if("function"!=typeof mu)return!1;try{r=new mu([1,3.14,-3.14,NaN]),t=bu(r)&&1===r[0]&&3.14===r[1]&&-3.14===r[2]&&r[3]!=r[3]}catch(r){t=!1}return t};var Eu,_u="function"==typeof Float64Array?Float64Array:void 0,Ou=function(){throw new Error("not implemented")};Eu=Au()?_u:Ou;var Pu=ii,ju=yi,Ru=_i,Tu=Bi,Uu=ki,Su=Ji,Iu=iu,Bu=vu,Yu=Eu;function xu(t){return new Pu(t)}function Cu(t){return new ju(t)}function Mu(t){return new Ru(t)}function Lu(t){return new Tu(t)}function Fu(t){return new Uu(t)}function Du(t){return new Su(t)}function Nu(t){return new Iu(t)}function ku(t){return new Bu(t)}function Vu(t){return new Yu(t)}var zu=O,Gu=Rt,Xu=Bt,$u=te,Hu=kt,Wu=ie,qu=Pe,Ju=Pn,Zu=Un,Ku=Yn,Qu=Zr,ta=p,ra=Jo,ea={int8array:xu,uint8array:Cu,uint8clampedarray:Mu,int16array:Lu,uint16array:Fu,int32array:Du,uint32array:Nu,float32array:ku,float64array:Vu};function na(t,r,e,n,o){var i,u,a,f,c,s,l,h,p,y;if(o-=1,"object"!=typeof t||null===t)return t;if(Xu(t))return ra(t);if($u(t))return function(t){var r,e,n,o,i,u,a=[],f=[];for(i=new t.constructor(t.message),a.push(t),f.push(i),t.stack&&(i.stack=t.stack),t.code&&(i.code=t.code),t.errno&&(i.errno=t.errno),t.syscall&&(i.syscall=t.syscall),r=Ju(t),u=0;u0)for(i=a,y=0;y1){if(!ia(r))throw new TypeError("invalid argument. `level` must be a nonnegative integer. Value: `"+r+"`.");if(0===r)return t}else r=ua;return e=oa(t)?new Array(t.length):{},aa(t,e,[t],[e],r)},ca=fa,sa=Rt;var la=function(t){return"object"==typeof t&&null!==t&&!sa(t)},ha=zt,pa=Zr,ya=O,va=I,ga=Object.prototype;var wa=function(t){var r;return!!la(t)&&(!(r=pa(t))||!ya(t,"constructor")&&ya(r,"constructor")&&ha(r.constructor)&&"[object Function]"===va(r.constructor)&&ya(r,"isPrototypeOf")&&ha(r.isPrototypeOf)&&(r===ga||function(t){var r;for(r in t)if(!ya(t,r))return!1;return!0}(t)))},da=wa,ba=O,ma=V.isPrimitive;var Aa={url:"https://stdlib.io/docs/api/latest/error-decoder.html",message:"Minified stdlib error code: {{code}}. Visit {{url}} for the full message."},Ea=Kt,_a=ca,Oa=function(t,r){return da(r)?ba(r,"url")&&(t.url=r.url,!ma(t.url))?new TypeError("invalid option. `url` option must be a string primitive. Option: `"+t.url+"`."):ba(r,"message")&&(t.message=r.message,!ma(t.message))?new TypeError("invalid option. `message` option must be a string primitive. Option: `"+t.message+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+r+"`.")},Pa=Aa;var ja=function(t){var r,e;if(r=_a(Pa),e=Oa(r,t))throw e;return function(){var t,e,n=arguments[0],o=r.url+"?code="+n;for(e=1;e=f&&(s=f-1);else if("wrap"===u)s<0?(s+=f)<0&&0!==(s%=f)&&(s+=f):s>=f&&(s-=f)>=f&&(s%=f);else if(s<0||s>=f)throw new RangeError(Ta("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",l,s));(c=t[l])<0&&0===r?a-=s*c:a+=s*c}return a}})); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index e1abfe1..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/utils-define-property/lib/define_property.js","../node_modules/@stdlib/utils-define-property/lib/has_define_property_support.js","../node_modules/@stdlib/utils-define-property/lib/builtin.js","../node_modules/@stdlib/utils-define-property/lib/polyfill.js","../node_modules/@stdlib/utils-define-property/lib/index.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/main.js","../node_modules/@stdlib/utils-define-nonenumerable-read-only-property/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/primitive.js","../node_modules/@stdlib/assert-has-symbol-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/main.js","../node_modules/@stdlib/assert-has-tostringtag-support/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostring.js","../node_modules/@stdlib/utils-native-class/lib/native_class.js","../node_modules/@stdlib/assert-has-own-property/lib/main.js","../node_modules/@stdlib/assert-has-own-property/lib/index.js","../node_modules/@stdlib/utils-native-class/lib/tostringtag.js","../node_modules/@stdlib/utils-native-class/lib/polyfill.js","../node_modules/@stdlib/utils-native-class/lib/index.js","../node_modules/@stdlib/assert-is-string/lib/try2valueof.js","../node_modules/@stdlib/assert-is-string/lib/valueof.js","../node_modules/@stdlib/assert-is-string/lib/object.js","../node_modules/@stdlib/assert-is-string/lib/main.js","../node_modules/@stdlib/assert-is-string/lib/index.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/main.js","../node_modules/@stdlib/utils-escape-regexp-string/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/re.js","../node_modules/@stdlib/assert-is-boolean/lib/primitive.js","../node_modules/@stdlib/assert-is-boolean/lib/try2serialize.js","../node_modules/@stdlib/assert-is-boolean/lib/tostring.js","../node_modules/@stdlib/assert-is-boolean/lib/object.js","../node_modules/@stdlib/assert-is-boolean/lib/main.js","../node_modules/@stdlib/assert-is-boolean/lib/index.js","../node_modules/@stdlib/utils-global/lib/codegen.js","../node_modules/@stdlib/utils-global/lib/self.js","../node_modules/@stdlib/utils-global/lib/window.js","../node_modules/@stdlib/utils-global/lib/global.js","../node_modules/@stdlib/utils-global/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/nodelist.js","../node_modules/@stdlib/utils-global/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/fixtures/typedarray.js","../node_modules/@stdlib/utils-type-of/lib/check.js","../node_modules/@stdlib/regexp-function-name/lib/main.js","../node_modules/@stdlib/regexp-function-name/lib/index.js","../node_modules/@stdlib/regexp-function-name/lib/regexp.js","../node_modules/@stdlib/assert-is-array/lib/main.js","../node_modules/@stdlib/assert-is-array/lib/index.js","../node_modules/@stdlib/assert-tools-array-function/lib/arrayfcn.js","../node_modules/@stdlib/assert-is-object-like/lib/main.js","../node_modules/@stdlib/assert-is-object-like/lib/index.js","../node_modules/@stdlib/assert-is-buffer/lib/main.js","../node_modules/@stdlib/assert-is-buffer/lib/index.js","../node_modules/@stdlib/utils-constructor-name/lib/main.js","../node_modules/@stdlib/utils-type-of/lib/typeof.js","../node_modules/@stdlib/utils-constructor-name/lib/index.js","../node_modules/@stdlib/utils-type-of/lib/polyfill.js","../node_modules/@stdlib/utils-type-of/lib/index.js","../node_modules/@stdlib/assert-is-function/lib/main.js","../node_modules/@stdlib/assert-is-function/lib/index.js","../node_modules/@stdlib/assert-is-regexp/lib/try2exec.js","../node_modules/@stdlib/assert-is-regexp/lib/exec.js","../node_modules/@stdlib/assert-is-regexp/lib/main.js","../node_modules/@stdlib/string-replace/lib/replace.js","../node_modules/@stdlib/string-replace/lib/index.js","../node_modules/@stdlib/assert-is-number/lib/primitive.js","../node_modules/@stdlib/number-ctor/lib/index.js","../node_modules/@stdlib/number-ctor/lib/number.js","../node_modules/@stdlib/assert-is-number/lib/try2serialize.js","../node_modules/@stdlib/assert-is-number/lib/tostring.js","../node_modules/@stdlib/assert-is-number/lib/object.js","../node_modules/@stdlib/assert-is-number/lib/main.js","../node_modules/@stdlib/assert-is-number/lib/index.js","../node_modules/@stdlib/constants-float64-pinf/lib/index.js","../node_modules/@stdlib/constants-float64-ninf/lib/index.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/is_integer.js","../node_modules/@stdlib/math-base-special-floor/lib/main.js","../node_modules/@stdlib/math-base-assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-integer/lib/integer.js","../node_modules/@stdlib/assert-is-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-integer/lib/object.js","../node_modules/@stdlib/assert-is-integer/lib/main.js","../node_modules/@stdlib/assert-is-integer/lib/index.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/primitive.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/object.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/main.js","../node_modules/@stdlib/assert-is-nonnegative-integer/lib/index.js","../node_modules/@stdlib/utils-get-prototype-of/lib/native.js","../node_modules/@stdlib/utils-get-prototype-of/lib/proto.js","../node_modules/@stdlib/utils-get-prototype-of/lib/polyfill.js","../node_modules/@stdlib/utils-get-prototype-of/lib/detect.js","../node_modules/@stdlib/utils-get-prototype-of/lib/get_prototype_of.js","../node_modules/@stdlib/utils-get-prototype-of/lib/index.js","../node_modules/@stdlib/assert-is-error/lib/main.js","../node_modules/@stdlib/assert-is-error/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/main.js","../node_modules/@stdlib/regexp-regexp/lib/index.js","../node_modules/@stdlib/regexp-regexp/lib/regexp.js","../node_modules/@stdlib/utils-regexp-from-string/lib/from_string.js","../node_modules/@stdlib/utils-regexp-from-string/lib/index.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/primitive.js","../node_modules/@stdlib/math-base-assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-nan/lib/object.js","../node_modules/@stdlib/assert-is-nan/lib/main.js","../node_modules/@stdlib/assert-is-nan/lib/index.js","../node_modules/@stdlib/assert-is-collection/lib/main.js","../node_modules/@stdlib/utils-index-of/lib/index_of.js","../node_modules/@stdlib/constants-array-max-typed-array-length/lib/index.js","../node_modules/@stdlib/utils-index-of/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin.js","../node_modules/@stdlib/utils-keys/lib/has_arguments_bug.js","../node_modules/@stdlib/utils-keys/lib/has_builtin.js","../node_modules/@stdlib/assert-is-arguments/lib/main.js","../node_modules/@stdlib/assert-is-arguments/lib/detect.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/has_string_enumerability_bug.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/native.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/main.js","../node_modules/@stdlib/assert-is-enumerable-property/lib/index.js","../node_modules/@stdlib/assert-is-arguments/lib/polyfill.js","../node_modules/@stdlib/assert-is-arguments/lib/index.js","../node_modules/@stdlib/utils-keys/lib/builtin_wrapper.js","../node_modules/@stdlib/utils-noop/lib/noop.js","../node_modules/@stdlib/utils-keys/lib/has_enumerable_prototype_bug.js","../node_modules/@stdlib/utils-keys/lib/has_non_enumerable_properties_bug.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype.js","../node_modules/@stdlib/utils-keys/lib/has_automation_equality_bug.js","../node_modules/@stdlib/utils-keys/lib/window.js","../node_modules/@stdlib/utils-keys/lib/has_window.js","../node_modules/@stdlib/utils-keys/lib/is_constructor_prototype_wrapper.js","../node_modules/@stdlib/utils-keys/lib/polyfill.js","../node_modules/@stdlib/utils-keys/lib/main.js","../node_modules/@stdlib/utils-keys/lib/index.js","../node_modules/@stdlib/utils-property-names/lib/has_builtin.js","../node_modules/@stdlib/utils-property-names/lib/builtin.js","../node_modules/@stdlib/utils-property-names/lib/polyfill.js","../node_modules/@stdlib/utils-property-names/lib/index.js","../node_modules/@stdlib/utils-property-descriptor/lib/has_builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/builtin.js","../node_modules/@stdlib/utils-property-descriptor/lib/polyfill.js","../node_modules/@stdlib/utils-property-descriptor/lib/index.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/buffer.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/main.js","../node_modules/@stdlib/assert-has-node-buffer-support/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/polyfill.js","../node_modules/@stdlib/buffer-ctor/lib/index.js","../node_modules/@stdlib/buffer-ctor/lib/buffer.js","../node_modules/@stdlib/buffer-from-buffer/lib/has_from.js","../node_modules/@stdlib/buffer-from-buffer/lib/main.js","../node_modules/@stdlib/buffer-from-buffer/lib/polyfill.js","../node_modules/@stdlib/buffer-from-buffer/lib/index.js","../node_modules/@stdlib/assert-is-int8array/lib/main.js","../node_modules/@stdlib/assert-has-int8array-support/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/main.js","../node_modules/@stdlib/constants-int8-min/lib/index.js","../node_modules/@stdlib/array-int8/lib/polyfill.js","../node_modules/@stdlib/array-int8/lib/index.js","../node_modules/@stdlib/array-int8/lib/int8array.js","../node_modules/@stdlib/assert-has-int8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8array/lib/main.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/main.js","../node_modules/@stdlib/array-uint8/lib/polyfill.js","../node_modules/@stdlib/array-uint8/lib/index.js","../node_modules/@stdlib/array-uint8/lib/uint8array.js","../node_modules/@stdlib/assert-has-uint8array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint8clampedarray/lib/main.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/main.js","../node_modules/@stdlib/array-uint8c/lib/polyfill.js","../node_modules/@stdlib/array-uint8c/lib/index.js","../node_modules/@stdlib/array-uint8c/lib/uint8clampedarray.js","../node_modules/@stdlib/assert-has-uint8clampedarray-support/lib/index.js","../node_modules/@stdlib/assert-is-int16array/lib/main.js","../node_modules/@stdlib/assert-has-int16array-support/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/main.js","../node_modules/@stdlib/constants-int16-min/lib/index.js","../node_modules/@stdlib/array-int16/lib/polyfill.js","../node_modules/@stdlib/array-int16/lib/index.js","../node_modules/@stdlib/array-int16/lib/int16array.js","../node_modules/@stdlib/assert-has-int16array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint16array/lib/main.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/main.js","../node_modules/@stdlib/array-uint16/lib/polyfill.js","../node_modules/@stdlib/array-uint16/lib/index.js","../node_modules/@stdlib/array-uint16/lib/uint16array.js","../node_modules/@stdlib/assert-has-uint16array-support/lib/index.js","../node_modules/@stdlib/assert-is-int32array/lib/main.js","../node_modules/@stdlib/assert-has-int32array-support/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/main.js","../node_modules/@stdlib/constants-int32-min/lib/index.js","../node_modules/@stdlib/array-int32/lib/polyfill.js","../node_modules/@stdlib/array-int32/lib/index.js","../node_modules/@stdlib/array-int32/lib/int32array.js","../node_modules/@stdlib/assert-has-int32array-support/lib/index.js","../node_modules/@stdlib/assert-is-uint32array/lib/main.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/main.js","../node_modules/@stdlib/array-uint32/lib/polyfill.js","../node_modules/@stdlib/array-uint32/lib/index.js","../node_modules/@stdlib/array-uint32/lib/uint32array.js","../node_modules/@stdlib/assert-has-uint32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float32array/lib/main.js","../node_modules/@stdlib/assert-has-float32array-support/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/main.js","../node_modules/@stdlib/array-float32/lib/polyfill.js","../node_modules/@stdlib/array-float32/lib/index.js","../node_modules/@stdlib/array-float32/lib/float32array.js","../node_modules/@stdlib/assert-has-float32array-support/lib/index.js","../node_modules/@stdlib/assert-is-float64array/lib/main.js","../node_modules/@stdlib/assert-has-float64array-support/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/main.js","../node_modules/@stdlib/array-float64/lib/polyfill.js","../node_modules/@stdlib/array-float64/lib/index.js","../node_modules/@stdlib/array-float64/lib/float64array.js","../node_modules/@stdlib/assert-has-float64array-support/lib/index.js","../node_modules/@stdlib/utils-copy/lib/typed_arrays.js","../node_modules/@stdlib/utils-copy/lib/deep_copy.js","../node_modules/@stdlib/utils-copy/lib/copy.js","../node_modules/@stdlib/utils-copy/lib/index.js","../node_modules/@stdlib/assert-is-object/lib/main.js","../node_modules/@stdlib/assert-is-plain-object/lib/main.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/validate.js","../node_modules/@stdlib/assert-is-plain-object/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/factory.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/index.js","../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\nvar main = ( typeof Object.defineProperty === 'function' ) ? Object.defineProperty : null;\n\n\n// EXPORTS //\n\nmodule.exports = main;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar defineProperty = require( './define_property.js' );\n\n\n// MAIN //\n\n/**\n* Tests for `Object.defineProperty` support.\n*\n* @private\n* @returns {boolean} boolean indicating if an environment has `Object.defineProperty` support\n*\n* @example\n* var bool = hasDefinePropertySupport();\n* // returns \n*/\nfunction hasDefinePropertySupport() {\n\t// Test basic support...\n\ttry {\n\t\tdefineProperty( {}, 'x', {} );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasDefinePropertySupport;\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// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @name defineProperty\n* @type {Function}\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nvar defineProperty = Object.defineProperty;\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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/* eslint-disable no-underscore-dangle, no-proto */\n\n'use strict';\n\n// VARIABLES //\n\nvar objectProtoype = Object.prototype;\nvar toStr = objectProtoype.toString;\nvar defineGetter = objectProtoype.__defineGetter__;\nvar defineSetter = objectProtoype.__defineSetter__;\nvar lookupGetter = objectProtoype.__lookupGetter__;\nvar lookupSetter = objectProtoype.__lookupSetter__;\n\n\n// MAIN //\n\n/**\n* Defines (or modifies) an object property.\n*\n* ## Notes\n*\n* - Property descriptors come in two flavors: **data descriptors** and **accessor descriptors**. A data descriptor is a property that has a value, which may or may not be writable. An accessor descriptor is a property described by a getter-setter function pair. A descriptor must be one of these two flavors and cannot be both.\n*\n* @param {Object} obj - object on which to define the property\n* @param {string} prop - property name\n* @param {Object} descriptor - property descriptor\n* @param {boolean} [descriptor.configurable=false] - boolean indicating if property descriptor can be changed and if the property can be deleted from the provided object\n* @param {boolean} [descriptor.enumerable=false] - boolean indicating if the property shows up when enumerating object properties\n* @param {boolean} [descriptor.writable=false] - boolean indicating if the value associated with the property can be changed with an assignment operator\n* @param {*} [descriptor.value] - property value\n* @param {(Function|void)} [descriptor.get=undefined] - function which serves as a getter for the property, or, if no getter, undefined. When the property is accessed, a getter function is called without arguments and with the `this` context set to the object through which the property is accessed (which may not be the object on which the property is defined due to inheritance). The return value will be used as the property value.\n* @param {(Function|void)} [descriptor.set=undefined] - function which serves as a setter for the property, or, if no setter, undefined. When assigning a property value, a setter function is called with one argument (the value being assigned to the property) and with the `this` context set to the object through which the property is assigned.\n* @throws {TypeError} first argument must be an object\n* @throws {TypeError} third argument must be an object\n* @throws {Error} property descriptor cannot have both a value and a setter and/or getter\n* @returns {Object} object with added property\n*\n* @example\n* var obj = {};\n*\n* defineProperty( obj, 'foo', {\n* 'value': 'bar'\n* });\n*\n* var str = obj.foo;\n* // returns 'bar'\n*/\nfunction defineProperty( obj, prop, descriptor ) {\n\tvar prototype;\n\tvar hasValue;\n\tvar hasGet;\n\tvar hasSet;\n\n\tif ( typeof obj !== 'object' || obj === null || toStr.call( obj ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an object. Value: `' + obj + '`.' );\n\t}\n\tif ( typeof descriptor !== 'object' || descriptor === null || toStr.call( descriptor ) === '[object Array]' ) {\n\t\tthrow new TypeError( 'invalid argument. Property descriptor must be an object. Value: `' + descriptor + '`.' );\n\t}\n\thasValue = ( 'value' in descriptor );\n\tif ( hasValue ) {\n\t\tif (\n\t\t\tlookupGetter.call( obj, prop ) ||\n\t\t\tlookupSetter.call( obj, prop )\n\t\t) {\n\t\t\t// Override `__proto__` to avoid touching inherited accessors:\n\t\t\tprototype = obj.__proto__;\n\t\t\tobj.__proto__ = objectProtoype;\n\n\t\t\t// Delete property as existing getters/setters prevent assigning value to specified property:\n\t\t\tdelete obj[ prop ];\n\t\t\tobj[ prop ] = descriptor.value;\n\n\t\t\t// Restore original prototype:\n\t\t\tobj.__proto__ = prototype;\n\t\t} else {\n\t\t\tobj[ prop ] = descriptor.value;\n\t\t}\n\t}\n\thasGet = ( 'get' in descriptor );\n\thasSet = ( 'set' in descriptor );\n\n\tif ( hasValue && ( hasGet || hasSet ) ) {\n\t\tthrow new Error( 'invalid argument. Cannot specify one or more accessors and a value or writable attribute in the property descriptor.' );\n\t}\n\n\tif ( hasGet && defineGetter ) {\n\t\tdefineGetter.call( obj, prop, descriptor.get );\n\t}\n\tif ( hasSet && defineSetter ) {\n\t\tdefineSetter.call( obj, prop, descriptor.set );\n\t}\n\treturn obj;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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* Define (or modify) an object property.\n*\n* @module @stdlib/utils-define-property\n*\n* @example\n* var defineProperty = require( '@stdlib/utils-define-property' );\n*\n* var obj = {};\n* defineProperty( obj, 'foo', {\n* 'value': 'bar',\n* 'writable': false,\n* 'configurable': false,\n* 'enumerable': false\n* });\n* obj.foo = 'boop'; // => throws\n*/\n\n// MODULES //\n\nvar hasDefinePropertySupport = require( './has_define_property_support.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar defineProperty;\nif ( hasDefinePropertySupport() ) {\n\tdefineProperty = builtin;\n} else {\n\tdefineProperty = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = defineProperty;\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\nvar defineProperty = require( '@stdlib/utils-define-property' );\n\n\n// MAIN //\n\n/**\n* Defines a non-enumerable read-only property.\n*\n* @param {Object} obj - object on which to define the property\n* @param {(string|symbol)} prop - property name\n* @param {*} value - value to set\n*\n* @example\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\nfunction setNonEnumerableReadOnly( obj, prop, value ) {\n\tdefineProperty( obj, prop, {\n\t\t'configurable': false,\n\t\t'enumerable': false,\n\t\t'writable': false,\n\t\t'value': value\n\t});\n}\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Define a non-enumerable read-only property.\n*\n* @module @stdlib/utils-define-nonenumerable-read-only-property\n*\n* @example\n* var setNonEnumerableReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\n*\n* var obj = {};\n*\n* setNonEnumerableReadOnly( obj, 'foo', 'bar' );\n*\n* try {\n* obj.foo = 'boop';\n* } catch ( err ) {\n* console.error( err.message );\n* }\n*/\n\n// MODULES //\n\nvar setNonEnumerableReadOnly = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = setNonEnumerableReadOnly;\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* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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// MAIN //\n\n/**\n* Tests for native `Symbol` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Symbol` support\n*\n* @example\n* var bool = hasSymbolSupport();\n* // returns \n*/\nfunction hasSymbolSupport() {\n\treturn (\n\t\ttypeof Symbol === 'function' &&\n\t\ttypeof Symbol( 'foo' ) === 'symbol'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasSymbolSupport;\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\nvar hasSymbols = require( '@stdlib/assert-has-symbol-support' );\n\n\n// VARIABLES //\n\nvar FLG = hasSymbols();\n\n\n// MAIN //\n\n/**\n* Tests for native `toStringTag` support.\n*\n* @returns {boolean} boolean indicating if an environment has `toStringTag` support\n*\n* @example\n* var bool = hasToStringTagSupport();\n* // returns \n*/\nfunction hasToStringTagSupport() {\n\treturn ( FLG && typeof Symbol.toStringTag === 'symbol' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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* Test for native `toStringTag` support.\n*\n* @module @stdlib/assert-has-tostringtag-support\n*\n* @example\n* var hasToStringTagSupport = require( '@stdlib/assert-has-tostringtag-support' );\n*\n* var bool = hasToStringTagSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasToStringTagSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasToStringTagSupport;\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// MAIN //\n\nvar toStr = Object.prototype.toString;\n\n\n// EXPORTS //\n\nmodule.exports = toStr;\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\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification (via the internal property `[[Class]]`) of an object.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\treturn toStr.call( v );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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// FUNCTIONS //\n\nvar has = Object.prototype.hasOwnProperty;\n\n\n// MAIN //\n\n/**\n* Tests if an object has a specified property.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object has a specified property\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'bap' );\n* // returns false\n*/\nfunction hasOwnProp( value, property ) {\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\treturn has.call( value, property );\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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* Test whether an object has a specified property.\n*\n* @module @stdlib/assert-has-own-property\n*\n* @example\n* var hasOwnProp = require( '@stdlib/assert-has-own-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = hasOwnProp( beep, 'boop' );\n* // returns true\n*\n* bool = hasOwnProp( beep, 'bop' );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasOwnProp = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasOwnProp;\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// MAIN //\n\nvar toStrTag = ( typeof Symbol === 'function' ) ? Symbol.toStringTag : '';\n\n\n// EXPORTS //\n\nmodule.exports = toStrTag;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar toStringTag = require( './tostringtag.js' );\nvar toStr = require( './tostring.js' );\n\n\n// MAIN //\n\n/**\n* Returns a string value indicating a specification defined classification of an object in environments supporting `Symbol.toStringTag`.\n*\n* @param {*} v - input value\n* @returns {string} string value indicating a specification defined classification of the input value\n*\n* @example\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* @example\n* var str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* @example\n* function Beep() {\n* return this;\n* }\n* var str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\nfunction nativeClass( v ) {\n\tvar isOwn;\n\tvar tag;\n\tvar out;\n\n\tif ( v === null || v === void 0 ) {\n\t\treturn toStr.call( v );\n\t}\n\ttag = v[ toStringTag ];\n\tisOwn = hasOwnProp( v, toStringTag );\n\n\t// Attempt to override the `toStringTag` property. For built-ins having a `Symbol.toStringTag` property (e.g., `JSON`, `Math`, etc), the `Symbol.toStringTag` property is read-only (e.g., , so we need to wrap in a `try/catch`.\n\ttry {\n\t\tv[ toStringTag ] = void 0;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn toStr.call( v );\n\t}\n\tout = toStr.call( v );\n\n\tif ( isOwn ) {\n\t\tv[ toStringTag ] = tag;\n\t} else {\n\t\tdelete v[ toStringTag ];\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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* Return a string value indicating a specification defined classification of an object.\n*\n* @module @stdlib/utils-native-class\n*\n* @example\n* var nativeClass = require( '@stdlib/utils-native-class' );\n*\n* var str = nativeClass( 'a' );\n* // returns '[object String]'\n*\n* str = nativeClass( 5 );\n* // returns '[object Number]'\n*\n* function Beep() {\n* return this;\n* }\n* str = nativeClass( new Beep() );\n* // returns '[object Object]'\n*/\n\n// MODULES //\n\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar builtin = require( './native_class.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar nativeClass;\nif ( hasToStringTag() ) {\n\tnativeClass = polyfill;\n} else {\n\tnativeClass = builtin;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nativeClass;\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\nvar valueOf = require( './valueof.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to extract a string value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a string can be extracted\n*/\nfunction test( value ) {\n\ttry {\n\t\tvalueOf.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar valueOf = String.prototype.valueOf; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = valueOf;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2valueof.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string object\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns false\n*/\nfunction isString( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof String ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object String]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a string.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a string\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*/\nfunction isString( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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* Test if a value is a string.\n*\n* @module @stdlib/assert-is-string\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' );\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 5 );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isObject;\n*\n* var bool = isString( new String( 'beep' ) );\n* // returns true\n*\n* bool = isString( 'beep' );\n* // returns false\n*\n* @example\n* var isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n*\n* var bool = isString( 'beep' );\n* // returns true\n*\n* bool = isString( new String( 'beep' ) );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isString = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isString, 'isPrimitive', isPrimitive );\nsetReadOnly( isString, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isString;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// VARIABLES //\n\nvar RE_CHARS = /[-\\/\\\\^$*+?.()|[\\]{}]/g; // eslint-disable-line no-useless-escape\n\n\n// MAIN //\n\n/**\n* Escapes a regular expression string.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} first argument must be a string primitive\n* @returns {string} escaped string\n*\n* @example\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\nfunction rescape( str ) {\n\tvar len;\n\tvar s;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Check if the string starts with a forward slash...\n\tif ( str[ 0 ] === '/' ) {\n\t\t// Find the last forward slash...\n\t\tlen = str.length;\n\t\tfor ( i = len-1; i >= 0; i-- ) {\n\t\t\tif ( str[ i ] === '/' ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t// If we searched the string to no avail or if the first letter is not `/`, assume that the string is not of the form `/[...]/[guimy]`:\n\tif ( i === void 0 || i <= 0 ) {\n\t\treturn str.replace( RE_CHARS, '\\\\$&' );\n\t}\n\t// We need to de-construct the string...\n\ts = str.substring( 1, i );\n\n\t// Only escape the characters between the `/`:\n\ts = s.replace( RE_CHARS, '\\\\$&' );\n\n\t// Reassemble:\n\tstr = str[ 0 ] + s + str.substring( i );\n\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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* Escape a regular expression string or pattern.\n*\n* @module @stdlib/utils-escape-regexp-string\n*\n* @example\n* var rescape = require( '@stdlib/utils-escape-regexp-string' );\n*\n* var str = rescape( '[A-Z]*' );\n* // returns '\\\\[A\\\\-Z\\\\]\\\\*'\n*/\n\n// MODULES //\n\nvar rescape = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rescape;\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\nvar RE = /./;\n\n\n// EXPORTS //\n\nmodule.exports = RE;\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* Tests if a value is a boolean primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean primitive\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns false\n*/\nfunction isBoolean( value ) {\n\treturn ( typeof value === 'boolean' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Boolean.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a boolean object\n*\n* @example\n* var bool = isBoolean( true );\n* // returns false\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Boolean ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Boolean]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a boolean.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a boolean\n*\n* @example\n* var bool = isBoolean( false );\n* // returns true\n*\n* @example\n* var bool = isBoolean( true );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* var bool = isBoolean( new Boolean( true ) );\n* // returns true\n*/\nfunction isBoolean( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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* Test if a value is a boolean.\n*\n* @module @stdlib/assert-is-boolean\n*\n* @example\n* var isBoolean = require( '@stdlib/assert-is-boolean' );\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*\n* @example\n* // Use interface to check for boolean primitives...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\n*\n* var bool = isBoolean( false );\n* // returns true\n*\n* bool = isBoolean( new Boolean( true ) );\n* // returns false\n*\n* @example\n* // Use interface to check for boolean objects...\n* var isBoolean = require( '@stdlib/assert-is-boolean' ).isObject;\n*\n* var bool = isBoolean( true );\n* // returns false\n*\n* bool = isBoolean( new Boolean( false ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isBoolean = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isBoolean, 'isPrimitive', isPrimitive );\nsetReadOnly( isBoolean, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isBoolean;\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// MAIN //\n\n/**\n* Returns the global object using code generation.\n*\n* @private\n* @returns {Object} global object\n*/\nfunction getGlobal() {\n\treturn new Function( 'return this;' )(); // eslint-disable-line no-new-func\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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// MAIN //\n\nvar obj = ( typeof self === 'object' ) ? self : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof window === 'object' ) ? window : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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// MAIN //\n\nvar obj = ( typeof global === 'object' ) ? global : null;\n\n\n// EXPORTS //\n\nmodule.exports = obj;\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\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar getThis = require( './codegen.js' );\nvar Self = require( './self.js' );\nvar Win = require( './window.js' );\nvar Global = require( './global.js' );\n\n\n// MAIN //\n\n/**\n* Returns the global object.\n*\n* ## Notes\n*\n* - Using code generation is the **most** reliable way to resolve the global object; however, doing so is likely to violate content security policies (CSPs) in, e.g., Chrome Apps and elsewhere.\n*\n* @param {boolean} [codegen=false] - boolean indicating whether to use code generation to resolve the global object\n* @throws {TypeError} must provide a boolean\n* @throws {Error} unable to resolve global object\n* @returns {Object} global object\n*\n* @example\n* var g = getGlobal();\n* // returns {...}\n*/\nfunction getGlobal( codegen ) {\n\tif ( arguments.length ) {\n\t\tif ( !isBoolean( codegen ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. Must provide a boolean primitive. Value: `'+codegen+'`.' );\n\t\t}\n\t\tif ( codegen ) {\n\t\t\treturn getThis();\n\t\t}\n\t\t// Fall through...\n\t}\n\t// Case: browsers and web workers\n\tif ( Self ) {\n\t\treturn Self;\n\t}\n\t// Case: browsers\n\tif ( Win ) {\n\t\treturn Win;\n\t}\n\t// Case: Node.js\n\tif ( Global ) {\n\t\treturn Global;\n\t}\n\t// Case: unknown\n\tthrow new Error( 'unexpected error. Unable to resolve global object.' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar getGlobal = require( '@stdlib/utils-global' );\n\n\n// MAIN //\n\nvar root = getGlobal();\nvar nodeList = root.document && root.document.childNodes;\n\n\n// EXPORTS //\n\nmodule.exports = nodeList;\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* Return the global object.\n*\n* @module @stdlib/utils-global\n*\n* @example\n* var getGlobal = require( '@stdlib/utils-global' );\n*\n* var g = getGlobal();\n* // returns {...}\n*/\n\n// MODULES //\n\nvar getGlobal = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getGlobal;\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\nvar typedarray = Int8Array; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = typedarray;\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\nvar RE = require( './fixtures/re.js' );\nvar nodeList = require( './fixtures/nodelist.js' );\nvar typedarray = require( './fixtures/typedarray.js' );\n\n\n// MAIN //\n\n/**\n* Checks whether a polyfill is needed when using the `typeof` operator.\n*\n* @private\n* @returns {boolean} boolean indicating whether a polyfill is needed\n*/\nfunction check() {\n\tif (\n\t\t// Chrome 1-12 returns 'function' for regular expression instances (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof):\n\t\ttypeof RE === 'function' ||\n\n\t\t// Safari 8 returns 'object' for typed array and weak map constructors (underscore #1929):\n\t\ttypeof typedarray === 'object' ||\n\n\t\t// PhantomJS 1.9 returns 'function' for `NodeList` instances (underscore #2236):\n\t\ttypeof nodeList === 'function'\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\nfunction reFunctionName() {\n\treturn /^\\s*function\\s*([^(]*)/i;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Regular expression to capture everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* @module @stdlib/regexp-function-name\n*\n* @example\n* var reFunctionName = require( '@stdlib/regexp-function-name' );\n* var RE_FUNCTION_NAME = reFunctionName();\n*\n* function fname( fcn ) {\n* return RE_FUNCTION_NAME.exec( fcn.toString() )[ 1 ];\n* }\n*\n* var fn = fname( Math.sqrt );\n* // returns 'sqrt'\n*\n* fn = fname( Int8Array );\n* // returns 'Int8Array'\n*\n* fn = fname( Object.prototype.toString );\n* // returns 'toString'\n*\n* fn = fname( function(){} );\n* // returns ''\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reFunctionName = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reFunctionName, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reFunctionName;\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\nvar reFunctionName = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Captures everything that is not a space immediately after the `function` keyword and before the first left parenthesis.\n*\n* Regular expression: `/^\\s*function\\s*([^(]*)/i`\n*\n* - `/^\\s*`\n* - Match zero or more spaces at beginning\n*\n* - `function`\n* - Match the word `function`\n*\n* - `\\s*`\n* - Match zero or more spaces after the word `function`\n*\n* - `()`\n* - Capture\n*\n* - `[^(]*`\n* - Match anything except a left parenthesis `(` zero or more times\n*\n* - `/i`\n* - ignore case\n*\n* @constant\n* @type {RegExp}\n* @default /^\\s*function\\s*([^(]*)/i\n*/\nvar RE_FUNCTION_NAME = reFunctionName();\n\n\n// EXPORTS //\n\nmodule.exports = RE_FUNCTION_NAME;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar f;\n\n\n// FUNCTIONS //\n\n/**\n* Tests if a value is an array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an array\n*\n* @example\n* var bool = isArray( [] );\n* // returns true\n*\n* @example\n* var bool = isArray( {} );\n* // returns false\n*/\nfunction isArray( value ) {\n\treturn ( nativeClass( value ) === '[object Array]' );\n}\n\n\n// MAIN //\n\nif ( Array.isArray ) {\n\tf = Array.isArray;\n} else {\n\tf = isArray;\n}\n\n\n// EXPORTS //\n\nmodule.exports = f;\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* Test if a value is an array.\n*\n* @module @stdlib/assert-is-array\n*\n* @example\n* var isArray = require( '@stdlib/assert-is-array' );\n*\n* var bool = isArray( [] );\n* // returns true\n*\n* bool = isArray( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isArray = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isArray;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Returns a function which tests if every element in an array passes a test condition.\n*\n* @param {Function} predicate - function to apply\n* @throws {TypeError} must provide a function\n* @returns {Function} an array function\n*\n* @example\n* var isOdd = require( '@stdlib/assert-is-odd' );\n*\n* var arr1 = [ 1, 3, 5, 7 ];\n* var arr2 = [ 3, 5, 8 ];\n*\n* var validate = arrayfcn( isOdd );\n*\n* var bool = validate( arr1 );\n* // returns true\n*\n* bool = validate( arr2 );\n* // returns false\n*/\nfunction arrayfcn( predicate ) {\n\tif ( typeof predicate !== 'function' ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a function. Value: `' + predicate + '`.' );\n\t}\n\treturn every;\n\n\t/**\n\t* Tests if every element in an array passes a test condition.\n\t*\n\t* @private\n\t* @param {*} value - value to test\n\t* @returns {boolean} boolean indicating whether a value is an array for which all elements pass a test condition\n\t*/\n\tfunction every( value ) {\n\t\tvar len;\n\t\tvar i;\n\t\tif ( !isArray( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tlen = value.length;\n\t\tif ( len === 0 ) {\n\t\t\treturn false;\n\t\t}\n\t\tfor ( i = 0; i < len; i++ ) {\n\t\t\tif ( predicate( value[ i ] ) === false ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = arrayfcn;\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* Tests if a value is object-like.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is object-like\n*\n* @example\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( [] );\n* // returns true\n*\n* @example\n* var bool = isObjectLike( null );\n* // returns false\n*/\nfunction isObjectLike( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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* Test if a value is object-like.\n*\n* @module @stdlib/assert-is-object-like\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' );\n*\n* var bool = isObjectLike( {} );\n* // returns true\n*\n* bool = isObjectLike( [] );\n* // returns true\n*\n* bool = isObjectLike( null );\n* // returns false\n*\n* @example\n* var isObjectLike = require( '@stdlib/assert-is-object-like' ).isObjectLikeArray;\n*\n* var bool = isObjectLike( [ {}, [] ] );\n* // returns true\n*\n* bool = isObjectLike( [ {}, '3.0' ] );\n* // returns false\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar arrayfun = require( '@stdlib/assert-tools-array-function' );\nvar isObjectLike = require( './main.js' );\n\n\n// MAIN //\n\nsetReadOnly( isObjectLike, 'isObjectLikeArray', arrayfun( isObjectLike ) );\n\n\n// EXPORTS //\n\nmodule.exports = isObjectLike;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Buffer instance.\n*\n* @param {*} value - value to validate\n* @returns {boolean} boolean indicating if a value is a Buffer instance\n*\n* @example\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( new Buffer( [1,2,3,4] ) );\n* // returns true\n*\n* @example\n* var v = isBuffer( {} );\n* // returns false\n*\n* @example\n* var v = isBuffer( [] );\n* // returns false\n*/\nfunction isBuffer( value ) {\n\treturn (\n\t\tisObjectLike( value ) &&\n\t\t(\n\t\t\t// eslint-disable-next-line no-underscore-dangle\n\t\t\tvalue._isBuffer || // for envs missing Object.prototype.constructor (e.g., Safari 5-7)\n\t\t\t(\n\t\t\t\tvalue.constructor &&\n\n\t\t\t\t// WARNING: `typeof` is not a foolproof check, as certain envs consider RegExp and NodeList instances to be functions\n\t\t\t\ttypeof value.constructor.isBuffer === 'function' &&\n\t\t\t\tvalue.constructor.isBuffer( value )\n\t\t\t)\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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* Test if a value is a Buffer instance.\n*\n* @module @stdlib/assert-is-buffer\n*\n* @example\n* var isBuffer = require( '@stdlib/assert-is-buffer' );\n*\n* var v = isBuffer( new Buffer( 'beep' ) );\n* // returns true\n*\n* v = isBuffer( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isBuffer = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar RE = require( '@stdlib/regexp-function-name' ).REGEXP;\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\n\n\n// MAIN //\n\n/**\n* Determines the name of a value's constructor.\n*\n* @param {*} v - input value\n* @returns {string} name of a value's constructor\n*\n* @example\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* @example\n* var v = constructorName( 5 );\n* // returns 'Number'\n*\n* @example\n* var v = constructorName( null );\n* // returns 'Null'\n*\n* @example\n* var v = constructorName( undefined );\n* // returns 'Undefined'\n*\n* @example\n* var v = constructorName( function noop() {} );\n* // returns 'Function'\n*/\nfunction constructorName( v ) {\n\tvar match;\n\tvar name;\n\tvar ctor;\n\tname = nativeClass( v ).slice( 8, -1 );\n\tif ( (name === 'Object' || name === 'Error') && v.constructor ) {\n\t\tctor = v.constructor;\n\t\tif ( typeof ctor.name === 'string' ) {\n\t\t\treturn ctor.name;\n\t\t}\n\t\tmatch = RE.exec( ctor.toString() );\n\t\tif ( match ) {\n\t\t\treturn match[ 1 ];\n\t\t}\n\t}\n\tif ( isBuffer( v ) ) {\n\t\treturn 'Buffer';\n\t}\n\treturn name;\n}\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// NOTES //\n\n/*\n* Built-in `typeof` operator behavior:\n*\n* ```text\n* typeof null => 'object'\n* typeof undefined => 'undefined'\n* typeof 'a' => 'string'\n* typeof 5 => 'number'\n* typeof NaN => 'number'\n* typeof true => 'boolean'\n* typeof false => 'boolean'\n* typeof {} => 'object'\n* typeof [] => 'object'\n* typeof function foo(){} => 'function'\n* typeof function* foo(){} => 'object'\n* typeof Symbol() => 'symbol'\n* ```\n*\n*/\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\tvar type;\n\n\t// Address `typeof null` => `object` (see http://wiki.ecmascript.org/doku.php?id=harmony:typeof_null):\n\tif ( v === null ) {\n\t\treturn 'null';\n\t}\n\ttype = typeof v;\n\n\t// If the `typeof` operator returned something other than `object`, we are done. Otherwise, we need to check for an internal class name or search for a constructor.\n\tif ( type === 'object' ) {\n\t\treturn ctorName( v ).toLowerCase();\n\t}\n\treturn type;\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine the name of a value's constructor.\n*\n* @module @stdlib/utils-constructor-name\n*\n* @example\n* var constructorName = require( '@stdlib/utils-constructor-name' );\n*\n* var v = constructorName( 'a' );\n* // returns 'String'\n*\n* v = constructorName( {} );\n* // returns 'Object'\n*\n* v = constructorName( true );\n* // returns 'Boolean'\n*/\n\n// MODULES //\n\nvar constructorName = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = constructorName;\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\nvar ctorName = require( '@stdlib/utils-constructor-name' );\n\n\n// MAIN //\n\n/**\n* Determines a value's type.\n*\n* @param {*} v - input value\n* @returns {string} string indicating the value's type\n*/\nfunction typeOf( v ) {\n\treturn ctorName( v ).toLowerCase();\n}\n\n\n// EXPORTS //\n\nmodule.exports = typeOf;\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* Determine a value's type.\n*\n* @module @stdlib/utils-type-of\n*\n* @example\n* var typeOf = require( '@stdlib/utils-type-of' );\n*\n* var str = typeOf( 'a' );\n* // returns 'string'\n*\n* str = typeOf( 5 );\n* // returns 'number'\n*/\n\n// MODULES //\n\nvar usePolyfill = require( './check.js' );\nvar typeOf = require( './typeof.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main = ( usePolyfill() ) ? polyfill : typeOf;\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar typeOf = require( '@stdlib/utils-type-of' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a function.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a function\n*\n* @example\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\nfunction isFunction( value ) {\n\t// Note: cannot use `typeof` directly, as various browser engines incorrectly return `'function'` when operating on non-function objects, such as regular expressions and NodeLists.\n\treturn ( typeOf( value ) === 'function' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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* Test if a value is a function.\n*\n* @module @stdlib/assert-is-function\n*\n* @example\n* var isFunction = require( '@stdlib/assert-is-function' );\n*\n* function beep() {\n* return 'beep';\n* }\n*\n* var bool = isFunction( beep );\n* // returns true\n*/\n\n// MODULES //\n\nvar isFunction = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isFunction;\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\nvar exec = require( './exec.js' );\n\n\n// MAIN //\n\n/**\n* Attempts to call a `RegExp` method.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if able to call a `RegExp` method\n*/\nfunction test( value ) {\n\ttry {\n\t\texec.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar exec = RegExp.prototype.exec; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = exec;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar test = require( './try2exec.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a regular expression.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a regular expression\n*\n* @example\n* var bool = isRegExp( /\\.+/ );\n* // returns true\n*\n* @example\n* var bool = isRegExp( {} );\n* // returns false\n*/\nfunction isRegExp( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof RegExp ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object RegExp]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isRegExp;\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\nvar rescape = require( '@stdlib/utils-escape-regexp-string' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isRegExp = require( '@stdlib/assert-is-regexp' );\n\n\n// MAIN //\n\n/**\n* Replace search occurrences with a replacement string.\n*\n* @param {string} str - input string\n* @param {(string|RegExp)} search - search expression\n* @param {(string|Function)} newval - replacement value or function\n* @throws {TypeError} first argument must be a string primitive\n* @throws {TypeError} second argument argument must be a string primitive or regular expression\n* @throws {TypeError} third argument must be a string primitive or function\n* @returns {string} new string containing replacement(s)\n*\n* @example\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* @example\n* var str = 'Hello World';\n* var out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*\n* @example\n* var capitalize = require( '@stdlib/string-capitalize' );\n*\n* var str = 'Oranges and lemons say the bells of St. Clement\\'s';\n*\n* function replacer( match, p1 ) {\n* return capitalize( p1 );\n* }\n*\n* var out = replace( str, /([^\\s]*)/gi, replacer);\n* // returns 'Oranges And Lemons Say The Bells Of St. Clement\\'s'\n*/\nfunction replace( str, search, newval ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be a string primitive. Value: `' + str + '`.' );\n\t}\n\tif ( isString( search ) ) {\n\t\tsearch = rescape( search );\n\t\tsearch = new RegExp( search, 'g' );\n\t}\n\telse if ( !isRegExp( search ) ) {\n\t\tthrow new TypeError( 'invalid argument. Second argument must be a string primitive or regular expression. Value: `' + search + '`.' );\n\t}\n\tif ( !isString( newval ) && !isFunction( newval ) ) {\n\t\tthrow new TypeError( 'invalid argument. Third argument must be a string primitive or replacement function. Value: `' + newval + '`.' );\n\t}\n\treturn str.replace( search, newval );\n}\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Replace search occurrences with a replacement string.\n*\n* @module @stdlib/string-replace\n*\n* @example\n* var replace = require( '@stdlib/string-replace' );\n*\n* var str = 'beep';\n* var out = replace( str, 'e', 'o' );\n* // returns 'boop'\n*\n* str = 'Hello World';\n* out = replace( str, /world/i, 'Mr. President' );\n* // returns 'Hello Mr. President'\n*/\n\n// MODULES //\n\nvar replace = require( './replace.js' );\n\n\n// EXPORTS //\n\nmodule.exports = replace;\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* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Constructor which returns a `Number` object.\n*\n* @module @stdlib/number-ctor\n*\n* @example\n* var Number = require( '@stdlib/number-ctor' );\n*\n* var v = new Number( 10.0 );\n* // returns \n*/\n\n// MODULES //\n\nvar Number = require( './number.js' );\n\n\n// EXPORTS //\n\nmodule.exports = Number;\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// EXPORTS //\n\nmodule.exports = Number; // eslint-disable-line stdlib/require-globals\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\nvar toString = require( './tostring.js' ); // eslint-disable-line stdlib/no-redeclare\n\n\n// MAIN //\n\n/**\n* Attempts to serialize a value to a string.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value can be serialized\n*/\nfunction test( value ) {\n\ttry {\n\t\ttoString.call( value );\n\t\treturn true;\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = test;\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\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n// eslint-disable-next-line stdlib/no-redeclare\nvar toString = Number.prototype.toString; // non-generic\n\n\n// EXPORTS //\n\nmodule.exports = toString;\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\nvar hasToStringTag = require( '@stdlib/assert-has-tostringtag-support' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar Number = require( '@stdlib/number-ctor' );\nvar test = require( './try2serialize.js' );\n\n\n// VARIABLES //\n\nvar FLG = hasToStringTag();\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\nfunction isNumber( value ) {\n\tif ( typeof value === 'object' ) {\n\t\tif ( value instanceof Number ) {\n\t\t\treturn true;\n\t\t}\n\t\tif ( FLG ) {\n\t\t\treturn test( value );\n\t\t}\n\t\treturn ( nativeClass( value ) === '[object Number]' );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a number\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( null );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Test if a value is a number.\n*\n* @module @stdlib/assert-is-number\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' );\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( null );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\n*\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* bool = isNumber( NaN );\n* // returns true\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*\n* @example\n* var isNumber = require( '@stdlib/assert-is-number' ).isObject;\n*\n* var bool = isNumber( 3.14 );\n* // returns false\n*\n* bool = isNumber( new Number( 3.14 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNumber = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNumber, 'isPrimitive', isPrimitive );\nsetReadOnly( isNumber, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNumber;\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* Double-precision floating-point positive infinity.\n*\n* @module @stdlib/constants-float64-pinf\n* @type {number}\n*\n* @example\n* var FLOAT64_PINF = require( '@stdlib/constants-float64-pinf' );\n* // returns Infinity\n*/\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point positive infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point positive infinity has the bit sequence\n*\n* ```binarystring\n* 0 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.POSITIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_PINF = Number.POSITIVE_INFINITY; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_PINF;\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* Double-precision floating-point negative infinity.\n*\n* @module @stdlib/constants-float64-ninf\n* @type {number}\n*\n* @example\n* var FLOAT64_NINF = require( '@stdlib/constants-float64-ninf' );\n* // returns -Infinity\n*/\n\n// MODULES //\n\nvar Number = require( '@stdlib/number-ctor' );\n\n\n// MAIN //\n\n/**\n* Double-precision floating-point negative infinity.\n*\n* ## Notes\n*\n* Double-precision floating-point negative infinity has the bit sequence\n*\n* ```binarystring\n* 1 11111111111 00000000000000000000 00000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {number}\n* @default Number.NEGATIVE_INFINITY\n* @see [IEEE 754]{@link https://en.wikipedia.org/wiki/IEEE_754-1985}\n*/\nvar FLOAT64_NINF = Number.NEGATIVE_INFINITY;\n\n\n// EXPORTS //\n\nmodule.exports = FLOAT64_NINF;\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\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// MAIN //\n\n/**\n* Tests if a finite double-precision floating-point number is an integer.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is an integer\n*\n* @example\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( 3.14 );\n* // returns false\n*/\nfunction isInteger( x ) {\n\treturn (floor(x) === x);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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// TODO: implementation (?)\n\n/**\n* Rounds a double-precision floating-point number toward negative infinity.\n*\n* @param {number} x - input value\n* @returns {number} rounded value\n*\n* @example\n* var v = floor( -4.2 );\n* // returns -5.0\n*\n* @example\n* var v = floor( 9.99999 );\n* // returns 9.0\n*\n* @example\n* var v = floor( 0.0 );\n* // returns 0.0\n*\n* @example\n* var v = floor( NaN );\n* // returns NaN\n*/\nvar floor = Math.floor; // eslint-disable-line stdlib/no-builtin-math\n\n\n// EXPORTS //\n\nmodule.exports = floor;\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* Test if a finite double-precision floating-point number is an integer.\n*\n* @module @stdlib/math-base-assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/math-base-assert-is-integer' );\n*\n* var bool = isInteger( 1.0 );\n* // returns true\n*\n* bool = isInteger( 3.14 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isInteger = require( './is_integer.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar isInt = require( '@stdlib/math-base-assert-is-integer' );\n\n\n// MAIN //\n\n/**\n* Tests if a number primitive is an integer value.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a number primitive is an integer value\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tvalue < PINF &&\n\t\tvalue > NINF &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having an integer value\n*\n* @example\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isInt = require( './integer.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having an integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having an integer value\n*\n* @example\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isInteger( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisInt( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an integer\n*\n* @example\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isInteger( -3.14 );\n* // returns false\n*\n* @example\n* var bool = isInteger( null );\n* // returns false\n*/\nfunction isInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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* Test if a value is an integer.\n*\n* @module @stdlib/assert-is-integer\n*\n* @example\n* var isInteger = require( '@stdlib/assert-is-integer' );\n*\n* var bool = isInteger( 5.0 );\n* // returns true\n*\n* bool = isInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isInteger( -3.14 );\n* // returns false\n*\n* bool = isInteger( null );\n* // returns false\n*\n* @example\n* // Use interface to check for integer primitives...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n*\n* var bool = isInteger( -3.0 );\n* // returns true\n*\n* bool = isInteger( new Number( -3.0 ) );\n* // returns false\n*\n* @example\n* // Use interface to check for integer objects...\n* var isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n*\n* var bool = isInteger( 3.0 );\n* // returns false\n*\n* bool = isInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number primitive having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isInteger = require( '@stdlib/assert-is-integer' ).isObject;\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a nonnegative integer value.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a nonnegative integer value\n*\n* @example\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn (\n\t\tisInteger( value ) &&\n\t\tvalue.valueOf() >= 0\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a nonnegative integer.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a nonnegative integer\n*\n* @example\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* @example\n* var bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isNonNegativeInteger( null );\n* // returns false\n*/\nfunction isNonNegativeInteger( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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* Test if a value is a nonnegative integer.\n*\n* @module @stdlib/assert-is-nonnegative-integer\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' );\n*\n* var bool = isNonNegativeInteger( 5.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 5.0 ) );\n* // returns true\n*\n* bool = isNonNegativeInteger( -5.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( 3.14 );\n* // returns false\n*\n* bool = isNonNegativeInteger( null );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns true\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns false\n*\n* @example\n* var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isObject;\n*\n* var bool = isNonNegativeInteger( 3.0 );\n* // returns false\n*\n* bool = isNonNegativeInteger( new Number( 3.0 ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isNonNegativeInteger = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isNonNegativeInteger, 'isPrimitive', isPrimitive );\nsetReadOnly( isNonNegativeInteger, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isNonNegativeInteger;\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// MAIN //\n\nvar getProto = Object.getPrototypeOf;\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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* Returns the value of the `__proto__` property.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {*} value of `__proto__` property\n*/\nfunction getProto( obj ) {\n\t// eslint-disable-next-line no-proto\n\treturn obj.__proto__;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\nvar getProto = require( './proto.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @private\n* @param {Object} obj - input object\n* @returns {(Object|null)} prototype\n*/\nfunction getPrototypeOf( obj ) {\n\tvar proto = getProto( obj );\n\tif ( proto || proto === null ) {\n\t\treturn proto;\n\t}\n\tif ( nativeClass( obj.constructor ) === '[object Function]' ) {\n\t\t// May break if the constructor has been tampered with...\n\t\treturn obj.constructor.prototype;\n\t}\n\tif ( obj instanceof Object ) {\n\t\treturn Object.prototype;\n\t}\n\t// Return `null` for objects created via `Object.create( null )`. Also return `null` for cross-realm objects on browsers that lack `__proto__` support, such as IE < 11.\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar builtin = require( './native.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar getProto;\nif ( isFunction( Object.getPrototypeOf ) ) {\n\tgetProto = builtin;\n} else {\n\tgetProto = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getProto;\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\nvar getProto = require( './detect.js' );\n\n\n// MAIN //\n\n/**\n* Returns the prototype of a provided object.\n*\n* @param {*} value - input value\n* @returns {(Object|null)} prototype\n*\n* @example\n* var proto = getPrototypeOf( {} );\n* // returns {}\n*/\nfunction getPrototypeOf( value ) {\n\tif (\n\t\tvalue === null ||\n\t\tvalue === void 0\n\t) {\n\t\treturn null;\n\t}\n\t// In order to ensure consistent ES5/ES6 behavior, cast input value to an object (strings, numbers, booleans); ES5 `Object.getPrototypeOf` throws when provided primitives and ES6 `Object.getPrototypeOf` casts:\n\tvalue = Object( value );\n\n\treturn getProto( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getPrototypeOf;\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* Return the prototype of a provided object.\n*\n* @module @stdlib/utils-get-prototype-of\n*\n* @example\n* var getPrototype = require( '@stdlib/utils-get-prototype-of' );\n*\n* var proto = getPrototype( {} );\n* // returns {}\n*/\n\n// MODULES //\n\nvar getPrototype = require( './get_prototype_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = getPrototype;\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\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an `Error` object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `Error` object\n*\n* @example\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* @example\n* var bool = isError( {} );\n* // returns false\n*/\nfunction isError( value ) {\n\tif ( typeof value !== 'object' || value === null ) {\n\t\treturn false;\n\t}\n\t// Check for `Error` objects from the same realm (same Node.js `vm` or same `Window` object)...\n\tif ( value instanceof Error ) {\n\t\treturn true;\n\t}\n\t// Walk the prototype tree until we find an object having the desired native class...\n\twhile ( value ) {\n\t\tif ( nativeClass( value ) === '[object Error]' ) {\n\t\t\treturn true;\n\t\t}\n\t\tvalue = getPrototypeOf( value );\n\t}\n\treturn false;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isError;\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* Test if a value is an `Error` object.\n*\n* @module @stdlib/assert-is-error\n*\n* @example\n* var isError = require( '@stdlib/assert-is-error' );\n*\n* var bool = isError( new Error( 'beep' ) );\n* // returns true\n*\n* bool = isError( {} );\n* // returns false\n*/\n\n// MODULES //\n\nvar isError = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isError;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Returns a regular expression to parse a regular expression string.\n*\n* @returns {RegExp} regular expression\n*\n* @example\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*/\nfunction reRegExp() {\n\treturn /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/; // eslint-disable-line no-useless-escape\n}\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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* Return a regular expression to parse a regular expression string.\n*\n* @module @stdlib/regexp-regexp\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var bool = RE_REGEXP.test( '/^beep$/' );\n* // returns true\n*\n* bool = RE_REGEXP.test( '' );\n* // returns false\n*\n* @example\n* var reRegExp = require( '@stdlib/regexp-regexp' );\n*\n* var RE_REGEXP = reRegExp();\n*\n* var parts = RE_REGEXP.exec( '/^.*$/ig' );\n* // returns [ '/^.*$/ig', '^.*$', 'ig', 'index': 0, 'input': '/^.*$/ig' ]\n*/\n\n// MAIN //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar reRegExp = require( './main.js' );\nvar REGEXP = require( './regexp.js' );\n\n\n// MAIN //\n\nsetReadOnly( reRegExp, 'REGEXP', REGEXP );\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\n\n\n// EXPORTS //\n\nmodule.exports = reRegExp;\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\nvar reRegExp = require( './main.js' );\n\n\n// MAIN //\n\n/**\n* Matches parts of a regular expression string.\n*\n* Regular expression: `/^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/`\n*\n* - `/^\\/`\n* - match a string that begins with a `/`\n*\n* - `()`\n* - capture\n*\n* - `(?:)+`\n* - capture, but do not remember, a group of characters which occur one or more times\n*\n* - `\\\\\\/`\n* - match the literal `\\/`\n*\n* - `|`\n* - OR\n*\n* - `[^\\/]`\n* - anything which is not the literal `\\/`\n*\n* - `\\/`\n* - match the literal `/`\n*\n* - `([imgy]*)`\n* - capture any characters matching `imgy` occurring zero or more times\n*\n* - `$/`\n* - string end\n*\n*\n* @constant\n* @type {RegExp}\n* @default /^\\/((?:\\\\\\/|[^\\/])+)\\/([imgy]*)$/\n*/\nvar RE_REGEXP = reRegExp();\n\n\n// EXPORTS //\n\nmodule.exports = RE_REGEXP;\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\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar reRegExp = require( '@stdlib/regexp-regexp' );\n\n\n// MAIN //\n\n/**\n* Parses a regular expression string and returns a new regular expression.\n*\n* @param {string} str - regular expression string\n* @throws {TypeError} must provide a regular expression string\n* @returns {(RegExp|null)} regular expression or null\n*\n* @example\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\nfunction reFromString( str ) {\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a regular expression string. Value: `' + str + '`.' );\n\t}\n\t// Capture the regular expression pattern and any flags:\n\tstr = reRegExp().exec( str );\n\n\t// Create a new regular expression:\n\treturn ( str ) ? new RegExp( str[1], str[2] ) : null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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* Create a regular expression from a regular expression string.\n*\n* @module @stdlib/utils-regexp-from-string\n*\n* @example\n* var reFromString = require( '@stdlib/utils-regexp-from-string' );\n*\n* var re = reFromString( '/beep/' );\n* // returns /beep/\n*/\n\n// MODULES //\n\nvar reFromString = require( './from_string.js' );\n\n\n// EXPORTS //\n\nmodule.exports = reFromString;\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// MAIN //\n\n/**\n* Tests if a double-precision floating-point numeric value is `NaN`.\n*\n* @param {number} x - value to test\n* @returns {boolean} boolean indicating whether the value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 7.0 );\n* // returns false\n*/\nfunction isnan( x ) {\n\treturn ( x !== x );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a `NaN` number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a `NaN` number primitive\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a double-precision floating-point numeric value is `NaN`.\n*\n* @module @stdlib/math-base-assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/math-base-assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 7.0 );\n* // returns false\n*/\n\n// MODULES //\n\nvar isnan = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isNumber = require( '@stdlib/assert-is-number' ).isObject;\nvar isNan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a number object having a value of `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number object having a value of `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns false\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*/\nfunction isnan( value ) {\n\treturn (\n\t\tisNumber( value ) &&\n\t\tisNan( value.valueOf() )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is `NaN`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is `NaN`\n*\n* @example\n* var bool = isnan( NaN );\n* // returns true\n*\n* @example\n* var bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* @example\n* var bool = isnan( 3.14 );\n* // returns false\n*\n* @example\n* var bool = isnan( null );\n* // returns false\n*/\nfunction isnan( value ) {\n\treturn ( isPrimitive( value ) || isObject( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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* Test if a value is `NaN`.\n*\n* @module @stdlib/assert-is-nan\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' );\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( null );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\n*\n* var bool = isnan( NaN );\n* // returns true\n*\n* bool = isnan( 3.14 );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns false\n*\n* @example\n* var isnan = require( '@stdlib/assert-is-nan' ).isObject;\n*\n* var bool = isnan( NaN );\n* // returns false\n*\n* bool = isnan( new Number( NaN ) );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar isnan = require( './main.js' );\nvar isPrimitive = require( './primitive.js' );\nvar isObject = require( './object.js' );\n\n\n// MAIN //\n\nsetReadOnly( isnan, 'isPrimitive', isPrimitive );\nsetReadOnly( isnan, 'isObject', isObject );\n\n\n// EXPORTS //\n\nmodule.exports = isnan;\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\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is a collection.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is a collection\n*\n* @example\n* var bool = isCollection( [] );\n* // returns true\n*\n* @example\n* var bool = isCollection( {} );\n* // returns false\n*/\nfunction isCollection( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isCollection;\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\nvar isnan = require( '@stdlib/assert-is-nan' );\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Returns the first index at which a given element can be found.\n*\n* @param {ArrayLike} arr - array-like object\n* @param {*} searchElement - element to find\n* @param {integer} [fromIndex] - starting index (if negative, the start index is determined relative to last element)\n* @throws {TypeError} must provide an array-like object\n* @throws {TypeError} `fromIndex` must be an integer\n* @returns {integer} index or -1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* @example\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 5 );\n* // returns -1\n*\n* @example\n* // Using a `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* @example\n* // `fromIndex` which exceeds `array` length:\n* var arr = [ 1, 2, 3, 4, 2, 5 ];\n* var idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* @example\n* // Negative `fromIndex`:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* var idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* @example\n* // Negative `fromIndex` exceeding input `array` length:\n* var arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* var idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* @example\n* // Array-like objects:\n* var str = 'bebop';\n* var idx = indexOf( str, 'o' );\n* // returns 3\n*/\nfunction indexOf( arr, searchElement, fromIndex ) {\n\tvar len;\n\tvar i;\n\tif ( !isCollection( arr ) && !isString( arr ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array-like object. Value: `' + arr + '`.' );\n\t}\n\tlen = arr.length;\n\tif ( len === 0 ) {\n\t\treturn -1;\n\t}\n\tif ( arguments.length === 3 ) {\n\t\tif ( !isInteger( fromIndex ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `fromIndex` must be an integer. Value: `' + fromIndex + '`.' );\n\t\t}\n\t\tif ( fromIndex >= 0 ) {\n\t\t\tif ( fromIndex >= len ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\ti = fromIndex;\n\t\t} else {\n\t\t\ti = len + fromIndex;\n\t\t\tif ( i < 0 ) {\n\t\t\t\ti = 0;\n\t\t\t}\n\t\t}\n\t} else {\n\t\ti = 0;\n\t}\n\t// Check for `NaN`...\n\tif ( isnan( searchElement ) ) {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( isnan( arr[i] ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfor ( ; i < len; i++ ) {\n\t\t\tif ( arr[ i ] === searchElement ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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* Maximum length of a typed array.\n*\n* @module @stdlib/constants-array-max-typed-array-length\n*\n* @example\n* var MAX_TYPED_ARRAY_LENGTH = require( '@stdlib/constants-array-max-typed-array-length' );\n* // returns 9007199254740991\n*/\n\n// MAIN //\n\n/**\n* Maximum length of a typed array.\n*\n* ```tex\n* 2^{53} - 1\n* ```\n*\n* @constant\n* @type {number}\n* @default 9007199254740991\n*/\nvar MAX_TYPED_ARRAY_LENGTH = 9007199254740991;\n\n\n// EXPORTS //\n\nmodule.exports = MAX_TYPED_ARRAY_LENGTH;\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* Return the first index at which a given element can be found.\n*\n* @module @stdlib/utils-index-of\n*\n* @example\n* var indexOf = require( '@stdlib/utils-index-of' );\n*\n* var arr = [ 4, 3, 2, 1 ];\n* var idx = indexOf( arr, 3 );\n* // returns 1\n*\n* arr = [ 4, 3, 2, 1 ];\n* idx = indexOf( arr, 5 );\n* // returns -1\n*\n* // Using a `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, 3 );\n* // returns 5\n*\n* // `fromIndex` which exceeds `array` length:\n* arr = [ 1, 2, 3, 4, 2, 5 ];\n* idx = indexOf( arr, 2, 10 );\n* // returns -1\n*\n* // Negative `fromIndex`:\n* arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n* idx = indexOf( arr, 2, -4 );\n* // returns 5\n*\n* idx = indexOf( arr, 2, -1 );\n* // returns 7\n*\n* // Negative `fromIndex` exceeding input `array` length:\n* arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n* idx = indexOf( arr, 2, -10 );\n* // returns 1\n*\n* // Array-like objects:\n* var str = 'bebop';\n* idx = indexOf( str, 'o' );\n* // returns 3\n*/\n\n// MODULES //\n\nvar indexOf = require( './index_of.js' );\n\n\n// EXPORTS //\n\nmodule.exports = indexOf;\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// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.keys()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\treturn Object.keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar keys = require( './builtin.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Tests the built-in `Object.keys()` implementation when provided `arguments`.\n*\n* @private\n* @returns {boolean} boolean indicating whether the built-in implementation returns the expected number of keys\n*/\nfunction test() {\n\treturn ( keys( arguments ) || '' ).length !== 2;\n}\n\n\n// MAIN //\n\n/**\n* Tests whether the built-in `Object.keys()` implementation supports providing `arguments` as an input value.\n*\n* ## Notes\n*\n* - Safari 5.0 does **not** support `arguments` as an input value.\n*\n* @private\n* @returns {boolean} boolean indicating whether a built-in implementation supports `arguments`\n*/\nfunction check() {\n\treturn test( 1, 2 );\n}\n\n\n// EXPORTS //\n\nmodule.exports = check;\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// MAIN //\n\nvar bool = ( typeof Object.keys !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn ( nativeClass( value ) === '[object Arguments]' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( './main.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment returns the expected internal class of the `arguments` object.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment behaves as expected\n*\n* @example\n* var bool = detect();\n* // returns \n*/\nfunction detect() {\n\treturn isArguments( arguments );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnum = require( './native.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Detects whether an environment has a bug where String indices are not detected as \"enumerable\" properties. Observed in Node v0.10.\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment has the bug\n*/\nfunction detect() {\n\treturn !isEnum.call( 'beep', '0' );\n}\n\n\n// MAIN //\n\nbool = detect();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @private\n* @name isEnumerableProperty\n* @type {Function}\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nvar isEnumerableProperty = Object.prototype.propertyIsEnumerable;\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar isString = require( '@stdlib/assert-is-string' );\nvar isnan = require( '@stdlib/assert-is-nan' ).isPrimitive;\nvar isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;\nvar isEnum = require( './native.js' );\nvar hasStringEnumBug = require( './has_string_enumerability_bug.js' );\n\n\n// MAIN //\n\n/**\n* Tests if an object's own property is enumerable.\n*\n* @param {*} value - value to test\n* @param {*} property - property to test\n* @returns {boolean} boolean indicating if an object property is enumerable\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* @example\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\nfunction isEnumerableProperty( value, property ) {\n\tvar bool;\n\tif (\n\t\tvalue === void 0 ||\n\t\tvalue === null\n\t) {\n\t\treturn false;\n\t}\n\tbool = isEnum.call( value, property );\n\tif ( !bool && hasStringEnumBug && isString( value ) ) {\n\t\t// Note: we only check for indices, as properties attached to a `String` object are properly detected as enumerable above.\n\t\tproperty = +property;\n\t\treturn (\n\t\t\t!isnan( property ) &&\n\t\t\tisInteger( property ) &&\n\t\t\tproperty >= 0 &&\n\t\t\tproperty < value.length\n\t\t);\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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* Test whether an object's own property is enumerable.\n*\n* @module @stdlib/assert-is-enumerable-property\n*\n* @example\n* var isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n*\n* var beep = {\n* 'boop': true\n* };\n*\n* var bool = isEnumerableProperty( beep, 'boop' );\n* // returns true\n*\n* bool = isEnumerableProperty( beep, 'hasOwnProperty' );\n* // returns false\n*/\n\n// MODULES //\n\nvar isEnumerableProperty = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isEnumerableProperty;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isInteger = require( '@stdlib/math-base-assert-is-integer' );\nvar MAX_LENGTH = require( '@stdlib/constants-uint32-max' );\n\n\n// MAIN //\n\n/**\n* Tests whether a value is an `arguments` object.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value is an `arguments` object\n*\n* @example\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* @example\n* var bool = isArguments( [] );\n* // returns false\n*/\nfunction isArguments( value ) {\n\treturn (\n\t\tvalue !== null &&\n\t\ttypeof value === 'object' &&\n\t\t!isArray( value ) &&\n\t\ttypeof value.length === 'number' &&\n\t\tisInteger( value.length ) &&\n\t\tvalue.length >= 0 &&\n\t\tvalue.length <= MAX_LENGTH &&\n\t\thasOwnProp( value, 'callee' ) &&\n\t\t!isEnumerableProperty( value, 'callee' )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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* Test if a value is an `arguments` object.\n*\n* @module @stdlib/assert-is-arguments\n*\n* @example\n* var isArguments = require( '@stdlib/assert-is-arguments' );\n*\n* function foo() {\n* return arguments;\n* }\n*\n* var bool = isArguments( foo() );\n* // returns true\n*\n* bool = isArguments( [] );\n* // returns false\n*/\n\n// MODULES //\n\nvar hasArgumentsClass = require( './detect.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar isArguments;\nif ( hasArgumentsClass ) {\n\tisArguments = main;\n} else {\n\tisArguments = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = isArguments;\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\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar builtin = require( './builtin.js' );\n\n\n// VARIABLES //\n\nvar slice = Array.prototype.slice;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tif ( isArguments( value ) ) {\n\t\treturn builtin( slice.call( value ) );\n\t}\n\treturn builtin( value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* No operation.\n*\n* @example\n* noop();\n* // ...does nothing.\n*/\nfunction noop() {\n\t// Empty function...\n}\n\n\n// EXPORTS //\n\nmodule.exports = noop;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\nvar noop = require( '@stdlib/utils-noop' );\n\n\n// MAIN //\n\n// Note: certain environments treat an object's prototype as enumerable, which, as a matter of convention, it shouldn't be...\nvar bool = isEnumerableProperty( noop, 'prototype' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isEnumerableProperty = require( '@stdlib/assert-is-enumerable-property' );\n\n\n// VARIABLES //\n\nvar obj = {\n\t'toString': null\n};\n\n\n// MAIN //\n\n// Note: certain environments don't allow enumeration of overwritten properties which are considered non-enumerable...\nvar bool = !isEnumerableProperty( obj, 'toString' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\n/**\n* Tests whether a value equals the prototype of its constructor.\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction isConstructorPrototype( value ) {\n\treturn ( value.constructor && value.constructor.prototype === value );\n}\n\n\n// EXPORTS //\n\nmodule.exports = isConstructorPrototype;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar EXCLUDED_KEYS = require( './excluded_keys.json' );\nvar win = require( './window.js' );\n\n\n// VARIABLES //\n\nvar bool;\n\n\n// FUNCTIONS //\n\n/**\n* Determines whether an environment throws when comparing to the prototype of a value's constructor (e.g., [IE9][1]).\n*\n* [1]: https://stackoverflow.com/questions/7688070/why-is-comparing-the-constructor-property-of-two-windows-unreliable\n*\n* @private\n* @returns {boolean} boolean indicating whether an environment is buggy\n*/\nfunction check() {\n\tvar k;\n\tif ( typeOf( win ) === 'undefined' ) {\n\t\treturn false;\n\t}\n\tfor ( k in win ) { // eslint-disable-line guard-for-in\n\t\ttry {\n\t\t\tif (\n\t\t\t\tindexOf( EXCLUDED_KEYS, k ) === -1 &&\n\t\t\t\thasOwnProp( win, k ) &&\n\t\t\t\twin[ k ] !== null &&\n\t\t\t\ttypeOf( win[ k ] ) === 'object'\n\t\t\t) {\n\t\t\t\tisConstructorPrototype( win[ k ] );\n\t\t\t}\n\t\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n\n// MAIN //\n\nbool = check();\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// MAIN //\n\nvar w = ( typeof window === 'undefined' ) ? void 0 : window;\n\n\n// EXPORTS //\n\nmodule.exports = w;\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// MAIN //\n\nvar bool = ( typeof window !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar hasAutomationEqualityBug = require( './has_automation_equality_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype.js' );\nvar HAS_WINDOW = require( './has_window.js' );\n\n\n// MAIN //\n\n/**\n* Wraps the test for constructor prototype equality to accommodate buggy environments (e.g., environments which throw when testing equality).\n*\n* @private\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether a value equals the prototype of its constructor\n*/\nfunction wrapper( value ) {\n\tif ( HAS_WINDOW === false && !hasAutomationEqualityBug ) {\n\t\treturn isConstructorPrototype( value );\n\t}\n\ttry {\n\t\treturn isConstructorPrototype( value );\n\t} catch ( error ) { // eslint-disable-line no-unused-vars\n\t\treturn false;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = wrapper;\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\nvar isObjectLike = require( '@stdlib/assert-is-object-like' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArguments = require( '@stdlib/assert-is-arguments' );\nvar HAS_ENUM_PROTO_BUG = require( './has_enumerable_prototype_bug.js' );\nvar HAS_NON_ENUM_PROPS_BUG = require( './has_non_enumerable_properties_bug.js' );\nvar isConstructorPrototype = require( './is_constructor_prototype_wrapper.js' );\nvar NON_ENUMERABLE = require( './non_enumerable.json' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction keys( value ) {\n\tvar skipConstructor;\n\tvar skipPrototype;\n\tvar isFcn;\n\tvar out;\n\tvar k;\n\tvar p;\n\tvar i;\n\n\tout = [];\n\tif ( isArguments( value ) ) {\n\t\t// Account for environments which treat `arguments` differently...\n\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\tout.push( i.toString() );\n\t\t}\n\t\t// Note: yes, we are precluding the `arguments` array-like object from having other enumerable properties; however, this should (1) be very rare and (2) not be encouraged (e.g., doing something like `arguments.a = 'b'`; in certain engines directly manipulating the `arguments` value results in automatic de-optimization).\n\t\treturn out;\n\t}\n\tif ( typeof value === 'string' ) {\n\t\t// Account for environments which do not treat string character indices as \"own\" properties...\n\t\tif ( value.length > 0 && !hasOwnProp( value, '0' ) ) {\n\t\t\tfor ( i = 0; i < value.length; i++ ) {\n\t\t\t\tout.push( i.toString() );\n\t\t\t}\n\t\t}\n\t} else {\n\t\tisFcn = ( typeof value === 'function' );\n\t\tif ( isFcn === false && !isObjectLike( value ) ) {\n\t\t\treturn out;\n\t\t}\n\t\tskipPrototype = ( HAS_ENUM_PROTO_BUG && isFcn );\n\t}\n\tfor ( k in value ) {\n\t\tif ( !( skipPrototype && k === 'prototype' ) && hasOwnProp( value, k ) ) {\n\t\t\tout.push( String( k ) );\n\t\t}\n\t}\n\tif ( HAS_NON_ENUM_PROPS_BUG ) {\n\t\tskipConstructor = isConstructorPrototype( value );\n\t\tfor ( i = 0; i < NON_ENUMERABLE.length; i++ ) {\n\t\t\tp = NON_ENUMERABLE[ i ];\n\t\t\tif ( !( skipConstructor && p === 'constructor' ) && hasOwnProp( value, p ) ) {\n\t\t\t\tout.push( String( p ) );\n\t\t\t}\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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\nvar hasArgumentsBug = require( './has_arguments_bug.js' );\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar wrapper = require( './builtin_wrapper.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable property names.\n*\n* @name keys\n* @type {Function}\n* @param {*} value - input object\n* @returns {Array} a list of own enumerable property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nvar keys;\nif ( HAS_BUILTIN ) {\n\tif ( hasArgumentsBug() ) {\n\t\tkeys = wrapper;\n\t} else {\n\t\tkeys = builtin;\n\t}\n} else {\n\tkeys = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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* Return an array of an object's own enumerable property names.\n*\n* @module @stdlib/utils-keys\n*\n* @example\n* var keys = require( '@stdlib/utils-keys' );\n*\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var k = keys( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\n\n// MODULES //\n\nvar keys = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = keys;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyNames !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyNames = Object.getOwnPropertyNames;\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn propertyNames( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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\nvar keys = require( '@stdlib/utils-keys' );\n\n\n// MAIN //\n\n/**\n* Returns an array of an object's own enumerable and non-enumerable property names.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyNames()`, this function returns an empty array if provided `undefined` or `null`, rather than throwing an error.\n* - In environments lacking support for `Object.getOwnPropertyNames()`, property descriptors are unavailable, and thus all properties can be safely assumed to be enumerable. Hence, we can defer to calling `Object.keys`, which retrieves all own enumerable property names.\n*\n* @private\n* @param {*} value - input object\n* @returns {Array} a list of own property names\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var keys = getOwnPropertyNames( obj );\n* // e.g., returns [ 'beep', 'foo' ]\n*/\nfunction getOwnPropertyNames( value ) {\n\treturn keys( Object( value ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyNames;\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* Return an array of an object's own enumerable and non-enumerable property names.\n*\n* @module @stdlib/utils-property-names\n*\n* @example\n* var getOwnPropertyNames = require( '@stdlib/utils-property-names' );\n*\n* var keys = getOwnPropertyNames({\n* 'foo': 'bar',\n* 'beep': 'boop'\n* });\n* // e.g., returns [ 'foo', 'beep' ]\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar bool = ( typeof Object.getOwnPropertyDescriptor !== 'undefined' );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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// VARIABLES //\n\nvar propertyDescriptor = Object.getOwnPropertyDescriptor;\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tvar desc;\n\tif ( value === null || value === void 0 ) {\n\t\treturn null;\n\t}\n\tdesc = propertyDescriptor( value, property );\n\treturn ( desc === void 0 ) ? null : desc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\n\n\n// MAIN //\n\n/**\n* Returns a property descriptor for an object's own property.\n*\n* ## Notes\n*\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if provided `undefined` or `null`, rather than throwing an error.\n* - In contrast to the built-in `Object.getOwnPropertyDescriptor()`, this function returns `null` if an object does not have a provided property, rather than `undefined`.\n* - In environments lacking `Object.getOwnPropertyDescriptor()` support, property descriptors do not exist. In non-supporting environment, if an object has a provided property, this function returns a descriptor object equivalent to that returned in a supporting environment; otherwise, the function returns `null`.\n*\n* @private\n* @param {*} value - input object\n* @param {(string|symbol)} property - property\n* @returns {(Object|null)} property descriptor or null\n*\n* @example\n* var obj = {\n* 'beep': 'boop',\n* 'foo': 3.14\n* };\n*\n* var desc = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':3.14}\n*/\nfunction getOwnPropertyDescriptor( value, property ) {\n\tif ( hasOwnProp( value, property ) ) {\n\t\treturn {\n\t\t\t'configurable': true,\n\t\t\t'enumerable': true,\n\t\t\t'writable': true,\n\t\t\t'value': value[ property ]\n\t\t};\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = getOwnPropertyDescriptor;\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* Return a property descriptor for an object's own property.\n*\n* @module @stdlib/utils-property-descriptor\n*\n* @example\n* var getOwnPropertyDescriptor = require( '@stdlib/utils-property-descriptor' );\n*\n* var obj = {\n* 'foo': 'bar',\n* 'beep': 'boop'\n* };\n*\n* var keys = getOwnPropertyDescriptor( obj, 'foo' );\n* // returns {'configurable':true,'enumerable':true,'writable':true,'value':'bar'}\n*/\n\n// MODULES //\n\nvar HAS_BUILTIN = require( './has_builtin.js' );\nvar builtin = require( './builtin.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar main;\nif ( HAS_BUILTIN ) {\n\tmain = builtin;\n} else {\n\tmain = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = main;\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// MAIN //\n\nvar main = ( typeof Buffer === 'function' ) ? Buffer : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar GlobalBuffer = require( './buffer.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Buffer` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Buffer` support\n*\n* @example\n* var bool = hasNodeBufferSupport();\n* // returns \n*/\nfunction hasNodeBufferSupport() {\n\tvar bool;\n\tvar b;\n\n\tif ( typeof GlobalBuffer !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tif ( typeof GlobalBuffer.from === 'function' ) {\n\t\t\tb = GlobalBuffer.from( [ 1, 2, 3, 4 ] );\n\t\t} else {\n\t\t\tb = new GlobalBuffer( [ 1, 2, 3, 4 ] ); // Note: this is deprecated behavior starting in Node v6 (see https://nodejs.org/api/buffer.html#buffer_new_buffer_array)\n\t\t}\n\t\tbool = (\n\t\t\tisBuffer( b ) &&\n\t\t\tb[ 0 ] === 1 &&\n\t\t\tb[ 1 ] === 2 &&\n\t\t\tb[ 2 ] === 3 &&\n\t\t\tb[ 3 ] === 4\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasNodeBufferSupport;\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* Test for native `Buffer` support.\n*\n* @module @stdlib/assert-has-node-buffer-support\n*\n* @example\n* var hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\n*\n* var bool = hasNodeBufferSupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasNodeBufferSupport;\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// TODO: write (browser) polyfill\n\n// MAIN //\n\n/**\n* Buffer constructor.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Buffer constructor.\n*\n* @module @stdlib/buffer-ctor\n*\n* @example\n* var ctor = require( '@stdlib/buffer-ctor' );\n*\n* var b = new ctor( [ 1, 2, 3, 4 ] );\n* // returns \n*/\n\n// MODULES //\n\nvar hasNodeBufferSupport = require( '@stdlib/assert-has-node-buffer-support' );\nvar main = require( './buffer.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasNodeBufferSupport() ) {\n\tctor = main;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = require( 'buffer' ).Buffer; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\nvar bool = isFunction( Buffer.from );\n\n\n// EXPORTS //\n\nmodule.exports = bool;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn Buffer.from( buffer );\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar Buffer = require( '@stdlib/buffer-ctor' );\n\n\n// MAIN //\n\n/**\n* Copies buffer data to a new `Buffer` instance.\n*\n* @param {Buffer} buffer - buffer from which to copy\n* @throws {TypeError} must provide a `Buffer` instance\n* @returns {Buffer} new `Buffer` instance\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = fromBuffer( b1 );\n* // returns \n*/\nfunction fromBuffer( buffer ) {\n\tif ( !isBuffer( buffer ) ) {\n\t\tthrow new TypeError( 'invalid argument. Must provide a Buffer. Value: `' + buffer + '`' );\n\t}\n\treturn new Buffer( buffer ); // eslint-disable-line no-buffer-constructor\n}\n\n\n// EXPORTS //\n\nmodule.exports = fromBuffer;\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* Copy buffer data to a new `Buffer` instance.\n*\n* @module @stdlib/buffer-from-buffer\n*\n* @example\n* var fromArray = require( '@stdlib/buffer-from-array' );\n* var copyBuffer = require( '@stdlib/buffer-from-buffer' );\n*\n* var b1 = fromArray( [ 1, 2, 3, 4 ] );\n* // returns \n*\n* var b2 = copyBuffer( b1 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFrom = require( './has_from.js' );\nvar main = require( './main.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar copyBuffer;\nif ( hasFrom ) {\n\tcopyBuffer = main;\n} else {\n\tcopyBuffer = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = copyBuffer;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt8Array = ( typeof Int8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int8Array\n*\n* @example\n* var bool = isInt8Array( new Int8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt8Array( [] );\n* // returns false\n*/\nfunction isInt8Array( value ) {\n\treturn (\n\t\t( hasInt8Array && value instanceof Int8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt8Array;\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// MAIN //\n\nvar main = ( typeof Int8Array === 'function' ) ? Int8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt8Array = require( '@stdlib/assert-is-int8array' );\nvar INT8_MAX = require( '@stdlib/constants-int8-max' );\nvar INT8_MIN = require( '@stdlib/constants-int8-min' );\nvar GlobalInt8Array = require( './int8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int8Array` support\n*\n* @example\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\nfunction hasInt8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt8Array( [ 1, 3.14, -3.14, INT8_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT8_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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* Minimum signed 8-bit integer.\n*\n* @module @stdlib/constants-int8-min\n* @type {integer32}\n*\n* @example\n* var INT8_MIN = require( '@stdlib/constants-int8-min' );\n* // returns -128\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 8-bit integer.\n*\n* ## Notes\n*\n* The number is given by\n*\n* ```tex\n* -(2^{7})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -128\n*/\nvar INT8_MIN = -128|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT8_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int8\n*\n* @example\n* var ctor = require( '@stdlib/array-int8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\nvar builtin = require( './int8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int8Array === 'function' ) ? Int8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int8Array` support.\n*\n* @module @stdlib/assert-has-int8array-support\n*\n* @example\n* var hasInt8ArraySupport = require( '@stdlib/assert-has-int8array-support' );\n*\n* var bool = hasInt8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8Array = ( typeof Uint8Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8Array\n*\n* @example\n* var bool = isUint8Array( new Uint8Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8Array( [] );\n* // returns false\n*/\nfunction isUint8Array( value ) {\n\treturn (\n\t\t( hasUint8Array && value instanceof Uint8Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8Array;\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// MAIN //\n\nvar main = ( typeof Uint8Array === 'function' ) ? Uint8Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8Array = require( '@stdlib/assert-is-uint8array' );\nvar UINT8_MAX = require( '@stdlib/constants-uint8-max' );\nvar GlobalUint8Array = require( './uint8array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8Array` support\n*\n* @example\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\nfunction hasUint8ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT8_MAX+1, UINT8_MAX+2 ];\n\t\tarr = new GlobalUint8Array( arr );\n\t\tbool = (\n\t\t\tisUint8Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT8_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint8\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\nvar builtin = require( './uint8array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8Array === 'function' ) ? Uint8Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8Array` support.\n*\n* @module @stdlib/assert-has-uint8array-support\n*\n* @example\n* var hasUint8ArraySupport = require( '@stdlib/assert-has-uint8array-support' );\n*\n* var bool = hasUint8ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint8ClampedArray = ( typeof Uint8ClampedArray === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint8ClampedArray.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint8ClampedArray\n*\n* @example\n* var bool = isUint8ClampedArray( new Uint8ClampedArray( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint8ClampedArray( [] );\n* // returns false\n*/\nfunction isUint8ClampedArray( value ) {\n\treturn (\n\t\t( hasUint8ClampedArray && value instanceof Uint8ClampedArray ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint8ClampedArray]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint8ClampedArray;\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// MAIN //\n\nvar main = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint8ClampedArray = require( '@stdlib/assert-is-uint8clampedarray' );\nvar GlobalUint8ClampedArray = require( './uint8clampedarray.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint8ClampedArray` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint8ClampedArray` support\n*\n* @example\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\nfunction hasUint8ClampedArraySupport() { // eslint-disable-line id-length\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint8ClampedArray !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalUint8ClampedArray( [ -1, 0, 1, 3.14, 4.99, 255, 256 ] );\n\t\tbool = (\n\t\t\tisUint8ClampedArray( arr ) &&\n\t\t\tarr[ 0 ] === 0 && // clamped\n\t\t\tarr[ 1 ] === 0 &&\n\t\t\tarr[ 2 ] === 1 &&\n\t\t\tarr[ 3 ] === 3 && // round to nearest\n\t\t\tarr[ 4 ] === 5 && // round to nearest\n\t\t\tarr[ 5 ] === 255 &&\n\t\t\tarr[ 6 ] === 255 // clamped\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.\n*\n* @module @stdlib/array-uint8c\n*\n* @example\n* var ctor = require( '@stdlib/array-uint8c' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' ); // eslint-disable-line id-length\nvar builtin = require( './uint8clampedarray.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint8ClampedArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint8ClampedArray === 'function' ) ? Uint8ClampedArray : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint8ClampedArray` support.\n*\n* @module @stdlib/assert-has-uint8clampedarray-support\n*\n* @example\n* var hasUint8ClampedArraySupport = require( '@stdlib/assert-has-uint8clampedarray-support' );\n*\n* var bool = hasUint8ClampedArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint8ClampedArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint8ClampedArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt16Array = ( typeof Int16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int16Array\n*\n* @example\n* var bool = isInt16Array( new Int16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt16Array( [] );\n* // returns false\n*/\nfunction isInt16Array( value ) {\n\treturn (\n\t\t( hasInt16Array && value instanceof Int16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt16Array;\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// MAIN //\n\nvar main = ( typeof Int16Array === 'function' ) ? Int16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt16Array = require( '@stdlib/assert-is-int16array' );\nvar INT16_MAX = require( '@stdlib/constants-int16-max' );\nvar INT16_MIN = require( '@stdlib/constants-int16-min' );\nvar GlobalInt16Array = require( './int16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int16Array` support\n*\n* @example\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\nfunction hasInt16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt16Array( [ 1, 3.14, -3.14, INT16_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT16_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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* Minimum signed 16-bit integer.\n*\n* @module @stdlib/constants-int16-min\n* @type {integer32}\n*\n* @example\n* var INT16_MIN = require( '@stdlib/constants-int16-min' );\n* // returns -32768\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 16-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{15})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 1000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -32768\n*/\nvar INT16_MIN = -32768|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT16_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int16\n*\n* @example\n* var ctor = require( '@stdlib/array-int16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\nvar builtin = require( './int16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int16Array === 'function' ) ? Int16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int16Array` support.\n*\n* @module @stdlib/assert-has-int16array-support\n*\n* @example\n* var hasInt16ArraySupport = require( '@stdlib/assert-has-int16array-support' );\n*\n* var bool = hasInt16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint16Array = ( typeof Uint16Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint16Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint16Array\n*\n* @example\n* var bool = isUint16Array( new Uint16Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint16Array( [] );\n* // returns false\n*/\nfunction isUint16Array( value ) {\n\treturn (\n\t\t( hasUint16Array && value instanceof Uint16Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint16Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint16Array;\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// MAIN //\n\nvar main = ( typeof Uint16Array === 'function' ) ? Uint16Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint16Array = require( '@stdlib/assert-is-uint16array' );\nvar UINT16_MAX = require( '@stdlib/constants-uint16-max' );\nvar GlobalUint16Array = require( './uint16array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint16Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint16Array` support\n*\n* @example\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\nfunction hasUint16ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint16Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT16_MAX+1, UINT16_MAX+2 ];\n\t\tarr = new GlobalUint16Array( arr );\n\t\tbool = (\n\t\t\tisUint16Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT16_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 16-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint16\n*\n* @example\n* var ctor = require( '@stdlib/array-uint16' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\nvar builtin = require( './uint16array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint16ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint16Array === 'function' ) ? Uint16Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint16Array` support.\n*\n* @module @stdlib/assert-has-uint16array-support\n*\n* @example\n* var hasUint16ArraySupport = require( '@stdlib/assert-has-uint16array-support' );\n*\n* var bool = hasUint16ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint16ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint16ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasInt32Array = ( typeof Int32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is an Int32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an Int32Array\n*\n* @example\n* var bool = isInt32Array( new Int32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isInt32Array( [] );\n* // returns false\n*/\nfunction isInt32Array( value ) {\n\treturn (\n\t\t( hasInt32Array && value instanceof Int32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Int32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isInt32Array;\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// MAIN //\n\nvar main = ( typeof Int32Array === 'function' ) ? Int32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isInt32Array = require( '@stdlib/assert-is-int32array' );\nvar INT32_MAX = require( '@stdlib/constants-int32-max' );\nvar INT32_MIN = require( '@stdlib/constants-int32-min' );\nvar GlobalInt32Array = require( './int32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Int32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Int32Array` support\n*\n* @example\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\nfunction hasInt32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalInt32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalInt32Array( [ 1, 3.14, -3.14, INT32_MAX+1 ] );\n\t\tbool = (\n\t\t\tisInt32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === -3 && // truncation\n\t\t\tarr[ 3 ] === INT32_MIN // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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* Minimum signed 32-bit integer.\n*\n* @module @stdlib/constants-int32-min\n* @type {integer32}\n*\n* @example\n* var INT32_MIN = require( '@stdlib/constants-int32-min' );\n* // returns -2147483648\n*/\n\n\n// MAIN //\n\n/**\n* Minimum signed 32-bit integer.\n*\n* ## Notes\n*\n* The number has the value\n*\n* ```tex\n* -(2^{31})\n* ```\n*\n* which corresponds to the two's complement bit sequence\n*\n* ```binarystring\n* 10000000000000000000000000000000\n* ```\n*\n* @constant\n* @type {integer32}\n* @default -2147483648\n*/\nvar INT32_MIN = -2147483648|0; // asm type annotation\n\n\n// EXPORTS //\n\nmodule.exports = INT32_MIN;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.\n*\n* @module @stdlib/array-int32\n*\n* @example\n* var ctor = require( '@stdlib/array-int32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\nvar builtin = require( './int32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasInt32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Int32Array === 'function' ) ? Int32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Int32Array` support.\n*\n* @module @stdlib/assert-has-int32array-support\n*\n* @example\n* var hasInt32ArraySupport = require( '@stdlib/assert-has-int32array-support' );\n*\n* var bool = hasInt32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasInt32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasInt32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasUint32Array = ( typeof Uint32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Uint32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Uint32Array\n*\n* @example\n* var bool = isUint32Array( new Uint32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isUint32Array( [] );\n* // returns false\n*/\nfunction isUint32Array( value ) {\n\treturn (\n\t\t( hasUint32Array && value instanceof Uint32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Uint32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isUint32Array;\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// MAIN //\n\nvar main = ( typeof Uint32Array === 'function' ) ? Uint32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isUint32Array = require( '@stdlib/assert-is-uint32array' );\nvar UINT32_MAX = require( '@stdlib/constants-uint32-max' );\nvar GlobalUint32Array = require( './uint32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Uint32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Uint32Array` support\n*\n* @example\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\nfunction hasUint32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalUint32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = [ 1, 3.14, -3.14, UINT32_MAX+1, UINT32_MAX+2 ];\n\t\tarr = new GlobalUint32Array( arr );\n\t\tbool = (\n\t\t\tisUint32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1 &&\n\t\t\tarr[ 1 ] === 3 && // truncation\n\t\t\tarr[ 2 ] === UINT32_MAX-2 && // truncation and wrap around\n\t\t\tarr[ 3 ] === 0 && // wrap around\n\t\t\tarr[ 4 ] === 1 // wrap around\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of 32-bit unsigned integers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.\n*\n* @module @stdlib/array-uint32\n*\n* @example\n* var ctor = require( '@stdlib/array-uint32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\nvar builtin = require( './uint32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasUint32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Uint32Array === 'function' ) ? Uint32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Uint32Array` support.\n*\n* @module @stdlib/assert-has-uint32array-support\n*\n* @example\n* var hasUint32ArraySupport = require( '@stdlib/assert-has-uint32array-support' );\n*\n* var bool = hasUint32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasUint32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasUint32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat32Array = ( typeof Float32Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float32Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float32Array\n*\n* @example\n* var bool = isFloat32Array( new Float32Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat32Array( [] );\n* // returns false\n*/\nfunction isFloat32Array( value ) {\n\treturn (\n\t\t( hasFloat32Array && value instanceof Float32Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float32Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat32Array;\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// MAIN //\n\nvar main = ( typeof Float32Array === 'function' ) ? Float32Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat32Array = require( '@stdlib/assert-is-float32array' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar GlobalFloat32Array = require( './float32array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float32Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float32Array` support\n*\n* @example\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\nfunction hasFloat32ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat32Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat32Array( [ 1.0, 3.14, -3.14, 5.0e40 ] );\n\t\tbool = (\n\t\t\tisFloat32Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.140000104904175 &&\n\t\t\tarr[ 2 ] === -3.140000104904175 &&\n\t\t\tarr[ 3 ] === PINF\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of single-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float32\n*\n* @example\n* var ctor = require( '@stdlib/array-float32' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\nvar builtin = require( './float32array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat32ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float32Array === 'function' ) ? Float32Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float32Array` support.\n*\n* @module @stdlib/assert-has-float32array-support\n*\n* @example\n* var hasFloat32ArraySupport = require( '@stdlib/assert-has-float32array-support' );\n*\n* var bool = hasFloat32ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat32ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat32ArraySupport;\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\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar hasFloat64Array = ( typeof Float64Array === 'function' ); // eslint-disable-line stdlib/require-globals\n\n\n// MAIN //\n\n/**\n* Tests if a value is a Float64Array.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a Float64Array\n*\n* @example\n* var bool = isFloat64Array( new Float64Array( 10 ) );\n* // returns true\n*\n* @example\n* var bool = isFloat64Array( [] );\n* // returns false\n*/\nfunction isFloat64Array( value ) {\n\treturn (\n\t\t( hasFloat64Array && value instanceof Float64Array ) || // eslint-disable-line stdlib/require-globals\n\t\tnativeClass( value ) === '[object Float64Array]'\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isFloat64Array;\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// MAIN //\n\nvar main = ( typeof Float64Array === 'function' ) ? Float64Array : null; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = main;\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\nvar isFloat64Array = require( '@stdlib/assert-is-float64array' );\nvar GlobalFloat64Array = require( './float64array.js' );\n\n\n// MAIN //\n\n/**\n* Tests for native `Float64Array` support.\n*\n* @returns {boolean} boolean indicating if an environment has `Float64Array` support\n*\n* @example\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\nfunction hasFloat64ArraySupport() {\n\tvar bool;\n\tvar arr;\n\n\tif ( typeof GlobalFloat64Array !== 'function' ) {\n\t\treturn false;\n\t}\n\t// Test basic support...\n\ttry {\n\t\tarr = new GlobalFloat64Array( [ 1.0, 3.14, -3.14, NaN ] );\n\t\tbool = (\n\t\t\tisFloat64Array( arr ) &&\n\t\t\tarr[ 0 ] === 1.0 &&\n\t\t\tarr[ 1 ] === 3.14 &&\n\t\t\tarr[ 2 ] === -3.14 &&\n\t\t\tarr[ 3 ] !== arr[ 3 ]\n\t\t);\n\t} catch ( err ) { // eslint-disable-line no-unused-vars\n\t\tbool = false;\n\t}\n\treturn bool;\n}\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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// TODO: write polyfill\n\n// MAIN //\n\n/**\n* Typed array which represents an array of double-precision floating-point numbers in the platform byte order.\n*\n* @throws {Error} not implemented\n*/\nfunction polyfill() {\n\tthrow new Error( 'not implemented' );\n}\n\n\n// EXPORTS //\n\nmodule.exports = polyfill;\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* Typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.\n*\n* @module @stdlib/array-float64\n*\n* @example\n* var ctor = require( '@stdlib/array-float64' );\n*\n* var arr = new ctor( 10 );\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\nvar builtin = require( './float64array.js' );\nvar polyfill = require( './polyfill.js' );\n\n\n// MAIN //\n\nvar ctor;\nif ( hasFloat64ArraySupport() ) {\n\tctor = builtin;\n} else {\n\tctor = polyfill;\n}\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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// MAIN //\n\nvar ctor = ( typeof Float64Array === 'function' ) ? Float64Array : void 0; // eslint-disable-line stdlib/require-globals\n\n\n// EXPORTS //\n\nmodule.exports = ctor;\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* Test for native `Float64Array` support.\n*\n* @module @stdlib/assert-has-float64array-support\n*\n* @example\n* var hasFloat64ArraySupport = require( '@stdlib/assert-has-float64array-support' );\n*\n* var bool = hasFloat64ArraySupport();\n* // returns \n*/\n\n// MODULES //\n\nvar hasFloat64ArraySupport = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = hasFloat64ArraySupport;\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\nvar Int8Array = require( '@stdlib/array-int8' );\nvar Uint8Array = require( '@stdlib/array-uint8' );\nvar Uint8ClampedArray = require( '@stdlib/array-uint8c' );\nvar Int16Array = require( '@stdlib/array-int16' );\nvar Uint16Array = require( '@stdlib/array-uint16' );\nvar Int32Array = require( '@stdlib/array-int32' );\nvar Uint32Array = require( '@stdlib/array-uint32' );\nvar Float32Array = require( '@stdlib/array-float32' );\nvar Float64Array = require( '@stdlib/array-float64' );\n\n\n// VARIABLES //\n\nvar hash;\n\n\n// FUNCTIONS //\n\n/**\n* Copies an `Int8Array`.\n*\n* @private\n* @param {Int8Array} arr - array to copy\n* @returns {Int8Array} new array\n*/\nfunction int8array( arr ) {\n\treturn new Int8Array( arr );\n}\n\n/**\n* Copies a `Uint8Array`.\n*\n* @private\n* @param {Uint8Array} arr - array to copy\n* @returns {Uint8Array} new array\n*/\nfunction uint8array( arr ) {\n\treturn new Uint8Array( arr );\n}\n\n/**\n* Copies a `Uint8ClampedArray`.\n*\n* @private\n* @param {Uint8ClampedArray} arr - array to copy\n* @returns {Uint8ClampedArray} new array\n*/\nfunction uint8clampedarray( arr ) {\n\treturn new Uint8ClampedArray( arr );\n}\n\n/**\n* Copies an `Int16Array`.\n*\n* @private\n* @param {Int16Array} arr - array to copy\n* @returns {Int16Array} new array\n*/\nfunction int16array( arr ) {\n\treturn new Int16Array( arr );\n}\n\n/**\n* Copies a `Uint16Array`.\n*\n* @private\n* @param {Uint16Array} arr - array to copy\n* @returns {Uint16Array} new array\n*/\nfunction uint16array( arr ) {\n\treturn new Uint16Array( arr );\n}\n\n/**\n* Copies an `Int32Array`.\n*\n* @private\n* @param {Int32Array} arr - array to copy\n* @returns {Int32Array} new array\n*/\nfunction int32array( arr ) {\n\treturn new Int32Array( arr );\n}\n\n/**\n* Copies a `Uint32Array`.\n*\n* @private\n* @param {Uint32Array} arr - array to copy\n* @returns {Uint32Array} new array\n*/\nfunction uint32array( arr ) {\n\treturn new Uint32Array( arr );\n}\n\n/**\n* Copies a `Float32Array`.\n*\n* @private\n* @param {Float32Array} arr - array to copy\n* @returns {Float32Array} new array\n*/\nfunction float32array( arr ) {\n\treturn new Float32Array( arr );\n}\n\n/**\n* Copies a `Float64Array`.\n*\n* @private\n* @param {Float64Array} arr - array to copy\n* @returns {Float64Array} new array\n*/\nfunction float64array( arr ) {\n\treturn new Float64Array( arr );\n}\n\n/**\n* Returns a hash of functions for copying typed arrays.\n*\n* @private\n* @returns {Object} function hash\n*/\nfunction typedarrays() {\n\tvar out = {\n\t\t'int8array': int8array,\n\t\t'uint8array': uint8array,\n\t\t'uint8clampedarray': uint8clampedarray,\n\t\t'int16array': int16array,\n\t\t'uint16array': uint16array,\n\t\t'int32array': int32array,\n\t\t'uint32array': uint32array,\n\t\t'float32array': float32array,\n\t\t'float64array': float64array\n\t};\n\treturn out;\n}\n\n\n// MAIN //\n\nhash = typedarrays();\n\n\n// EXPORTS //\n\nmodule.exports = hash;\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\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isBuffer = require( '@stdlib/assert-is-buffer' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar typeOf = require( '@stdlib/utils-type-of' );\nvar regexp = require( '@stdlib/utils-regexp-from-string' );\nvar indexOf = require( '@stdlib/utils-index-of' );\nvar objectKeys = require( '@stdlib/utils-keys' );\nvar propertyNames = require( '@stdlib/utils-property-names' );\nvar propertyDescriptor = require( '@stdlib/utils-property-descriptor' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar defineProperty = require( '@stdlib/utils-define-property' );\nvar copyBuffer = require( '@stdlib/buffer-from-buffer' );\nvar typedArrays = require( './typed_arrays.js' );\n\n\n// FUNCTIONS //\n\n/**\n* Clones a class instance.\n*\n* ## Notes\n*\n* - This should **only** be used for simple cases. Any instances with privileged access to variables (e.g., within closures) cannot be cloned. This approach should be considered **fragile**.\n* - The function is greedy, disregarding the notion of a `level`. Instead, the function deep copies all properties, as we assume the concept of `level` applies only to the class instance reference but not to its internal state. This prevents, in theory, two instances from sharing state.\n*\n*\n* @private\n* @param {Object} val - class instance\n* @returns {Object} new instance\n*/\nfunction cloneInstance( val ) {\n\tvar cache;\n\tvar names;\n\tvar name;\n\tvar refs;\n\tvar desc;\n\tvar tmp;\n\tvar ref;\n\tvar i;\n\n\tcache = [];\n\trefs = [];\n\n\tref = Object.create( getPrototypeOf( val ) );\n\tcache.push( val );\n\trefs.push( ref );\n\n\tnames = propertyNames( val );\n\tfor ( i = 0; i < names.length; i++ ) {\n\t\tname = names[ i ];\n\t\tdesc = propertyDescriptor( val, name );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( val[name] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( val[name], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( ref, name, desc );\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( ref );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( ref );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( ref );\n\t}\n\treturn ref;\n}\n\n/**\n* Copies an error object.\n*\n* @private\n* @param {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error - error to copy\n* @returns {(Error|TypeError|SyntaxError|URIError|ReferenceError|RangeError|EvalError)} error copy\n*\n* @example\n* var err1 = new TypeError( 'beep' );\n*\n* var err2 = copyError( err1 );\n* // returns \n*/\nfunction copyError( error ) {\n\tvar cache = [];\n\tvar refs = [];\n\tvar keys;\n\tvar desc;\n\tvar tmp;\n\tvar key;\n\tvar err;\n\tvar i;\n\n\t// Create a new error...\n\terr = new error.constructor( error.message );\n\n\tcache.push( error );\n\trefs.push( err );\n\n\t// If a `stack` property is present, copy it over...\n\tif ( error.stack ) {\n\t\terr.stack = error.stack;\n\t}\n\t// Node.js specific (system errors)...\n\tif ( error.code ) {\n\t\terr.code = error.code;\n\t}\n\tif ( error.errno ) {\n\t\terr.errno = error.errno;\n\t}\n\tif ( error.syscall ) {\n\t\terr.syscall = error.syscall;\n\t}\n\t// Any enumerable properties...\n\tkeys = objectKeys( error );\n\tfor ( i = 0; i < keys.length; i++ ) {\n\t\tkey = keys[ i ];\n\t\tdesc = propertyDescriptor( error, key );\n\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\ttmp = ( isArray( error[ key ] ) ) ? [] : {};\n\t\t\tdesc.value = deepCopy( error[ key ], tmp, cache, refs, -1 );\n\t\t}\n\t\tdefineProperty( err, key, desc );\n\t}\n\treturn err;\n}\n\n\n// MAIN //\n\n/**\n* Recursively performs a deep copy of an input object.\n*\n* @private\n* @param {*} val - value to copy\n* @param {(Array|Object)} copy - copy\n* @param {Array} cache - an array of visited objects\n* @param {Array} refs - an array of object references\n* @param {NonNegativeInteger} level - copy depth\n* @returns {*} deep copy\n*/\nfunction deepCopy( val, copy, cache, refs, level ) {\n\tvar parent;\n\tvar keys;\n\tvar name;\n\tvar desc;\n\tvar ctor;\n\tvar key;\n\tvar ref;\n\tvar x;\n\tvar i;\n\tvar j;\n\n\tlevel -= 1;\n\n\t// Primitives and functions...\n\tif (\n\t\ttypeof val !== 'object' ||\n\t\tval === null\n\t) {\n\t\treturn val;\n\t}\n\tif ( isBuffer( val ) ) {\n\t\treturn copyBuffer( val );\n\t}\n\tif ( isError( val ) ) {\n\t\treturn copyError( val );\n\t}\n\t// Objects...\n\tname = typeOf( val );\n\n\tif ( name === 'date' ) {\n\t\treturn new Date( +val );\n\t}\n\tif ( name === 'regexp' ) {\n\t\treturn regexp( val.toString() );\n\t}\n\tif ( name === 'set' ) {\n\t\treturn new Set( val );\n\t}\n\tif ( name === 'map' ) {\n\t\treturn new Map( val );\n\t}\n\tif (\n\t\tname === 'string' ||\n\t\tname === 'boolean' ||\n\t\tname === 'number'\n\t) {\n\t\t// If provided an `Object`, return an equivalent primitive!\n\t\treturn val.valueOf();\n\t}\n\tctor = typedArrays[ name ];\n\tif ( ctor ) {\n\t\treturn ctor( val );\n\t}\n\t// Class instances...\n\tif (\n\t\tname !== 'array' &&\n\t\tname !== 'object'\n\t) {\n\t\t// Cloning requires ES5 or higher...\n\t\tif ( typeof Object.freeze === 'function' ) {\n\t\t\treturn cloneInstance( val );\n\t\t}\n\t\treturn {};\n\t}\n\t// Arrays and plain objects...\n\tkeys = objectKeys( val );\n\tif ( level > 0 ) {\n\t\tparent = name;\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tx = val[ key ];\n\n\t\t\t// Primitive, Buffer, special class instance...\n\t\t\tname = typeOf( x );\n\t\t\tif (\n\t\t\t\ttypeof x !== 'object' ||\n\t\t\t\tx === null ||\n\t\t\t\t(\n\t\t\t\t\tname !== 'array' &&\n\t\t\t\t\tname !== 'object'\n\t\t\t\t) ||\n\t\t\t\tisBuffer( x )\n\t\t\t) {\n\t\t\t\tif ( parent === 'object' ) {\n\t\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\t\tdesc.value = deepCopy( x );\n\t\t\t\t\t}\n\t\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t\t} else {\n\t\t\t\t\tcopy[ key ] = deepCopy( x );\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Circular reference...\n\t\t\ti = indexOf( cache, x );\n\t\t\tif ( i !== -1 ) {\n\t\t\t\tcopy[ key ] = refs[ i ];\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Plain array or object...\n\t\t\tref = ( isArray( x ) ) ? new Array( x.length ) : {};\n\t\t\tcache.push( x );\n\t\t\trefs.push( ref );\n\t\t\tif ( parent === 'array' ) {\n\t\t\t\tcopy[ key ] = deepCopy( x, ref, cache, refs, level );\n\t\t\t} else {\n\t\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\t\tif ( hasOwnProp( desc, 'value' ) ) {\n\t\t\t\t\tdesc.value = deepCopy( x, ref, cache, refs, level );\n\t\t\t\t}\n\t\t\t\tdefineProperty( copy, key, desc );\n\t\t\t}\n\t\t}\n\t} else if ( name === 'array' ) {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tcopy[ key ] = val[ key ];\n\t\t}\n\t} else {\n\t\tfor ( j = 0; j < keys.length; j++ ) {\n\t\t\tkey = keys[ j ];\n\t\t\tdesc = propertyDescriptor( val, key );\n\t\t\tdefineProperty( copy, key, desc );\n\t\t}\n\t}\n\tif ( !Object.isExtensible( val ) ) {\n\t\tObject.preventExtensions( copy );\n\t}\n\tif ( Object.isSealed( val ) ) {\n\t\tObject.seal( copy );\n\t}\n\tif ( Object.isFrozen( val ) ) {\n\t\tObject.freeze( copy );\n\t}\n\treturn copy;\n}\n\n\n// EXPORTS //\n\nmodule.exports = deepCopy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\nvar isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive;\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar deepCopy = require( './deep_copy.js' );\n\n\n// MAIN //\n\n/**\n* Copies or deep clones a value to an arbitrary depth.\n*\n* @param {*} value - value to copy\n* @param {NonNegativeInteger} [level=+infinity] - copy depth\n* @throws {TypeError} `level` must be a nonnegative integer\n* @returns {*} value copy\n*\n* @example\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ { 'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\nfunction copy( value, level ) {\n\tvar out;\n\tif ( arguments.length > 1 ) {\n\t\tif ( !isNonNegativeInteger( level ) ) {\n\t\t\tthrow new TypeError( 'invalid argument. `level` must be a nonnegative integer. Value: `' + level + '`.' );\n\t\t}\n\t\tif ( level === 0 ) {\n\t\t\treturn value;\n\t\t}\n\t} else {\n\t\tlevel = PINF;\n\t}\n\tout = ( isArray( value ) ) ? new Array( value.length ) : {};\n\treturn deepCopy( value, out, [value], [out], level );\n}\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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* Copy or deep clone a value to an arbitrary depth.\n*\n* @module @stdlib/utils-copy\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var out = copy( 'beep' );\n* // returns 'beep'\n*\n* @example\n* var copy = require( '@stdlib/utils-copy' );\n*\n* var value = [\n* {\n* 'a': 1,\n* 'b': true,\n* 'c': [ 1, 2, 3 ]\n* }\n* ];\n* var out = copy( value );\n* // returns [ {'a': 1, 'b': true, 'c': [ 1, 2, 3 ] } ]\n*\n* var bool = ( value[0].c === out[0].c );\n* // returns false\n*/\n\n// MODULES //\n\nvar copy = require( './copy.js' );\n\n\n// EXPORTS //\n\nmodule.exports = copy;\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\nvar isArray = require( '@stdlib/assert-is-array' );\n\n\n// MAIN //\n\n/**\n* Tests if a value is an object; e.g., `{}`.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is an object\n*\n* @example\n* var bool = isObject( {} );\n* // returns true\n*\n* @example\n* var bool = isObject( null );\n* // returns false\n*/\nfunction isObject( value ) {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t!isArray( value )\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isObject;\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\nvar isObject = require( '@stdlib/assert-is-object' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar getPrototypeOf = require( '@stdlib/utils-get-prototype-of' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar nativeClass = require( '@stdlib/utils-native-class' );\n\n\n// VARIABLES //\n\nvar objectPrototype = Object.prototype;\n\n\n// FUNCTIONS //\n\n/**\n* Tests that an object only has own properties.\n*\n* @private\n* @param {Object} obj - value to test\n* @returns {boolean} boolean indicating if an object only has own properties\n*/\nfunction ownProps( obj ) {\n\tvar key;\n\n\t// NOTE: possibility of perf boost if key enumeration order is known (see http://stackoverflow.com/questions/18531624/isplainobject-thing).\n\tfor ( key in obj ) {\n\t\tif ( !hasOwnProp( obj, key ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\n\n// MAIN //\n\n/**\n* Tests if a value is a plain object.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating whether value is a plain object\n*\n* @example\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* @example\n* var bool = isPlainObject( null );\n* // returns false\n*/\nfunction isPlainObject( value ) {\n\tvar proto;\n\n\t// Screen for obvious non-objects...\n\tif ( !isObject( value ) ) {\n\t\treturn false;\n\t}\n\t// Objects with no prototype (e.g., `Object.create( null )`) are plain...\n\tproto = getPrototypeOf( value );\n\tif ( !proto ) {\n\t\treturn true;\n\t}\n\t// Objects having a prototype are plain if and only if they are constructed with a global `Object` function and the prototype points to the prototype of a plain object...\n\treturn (\n\t\t// Cannot have own `constructor` property:\n\t\t!hasOwnProp( value, 'constructor' ) &&\n\n\t\t// Prototype `constructor` property must be a function (see also https://bugs.jquery.com/ticket/9897 and http://stackoverflow.com/questions/18531624/isplainobject-thing):\n\t\thasOwnProp( proto, 'constructor' ) &&\n\t\tisFunction( proto.constructor ) &&\n\t\tnativeClass( proto.constructor ) === '[object Function]' &&\n\n\t\t// Test for object-specific method:\n\t\thasOwnProp( proto, 'isPrototypeOf' ) &&\n\t\tisFunction( proto.isPrototypeOf ) &&\n\n\t\t(\n\t\t\t// Test if the prototype matches the global `Object` prototype (same realm):\n\t\t\tproto === objectPrototype ||\n\n\t\t\t// Test that all properties are own properties (cross-realm; *most* likely a plain object):\n\t\t\townProps( value )\n\t\t)\n\t);\n}\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isString = require( '@stdlib/assert-is-string' ).isPrimitive;\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - options to validate\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {(Error|null)} error object or null\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( 'invalid argument. Options argument must be an object. Value: `' + options + '`.' );\n\t}\n\tif ( hasOwnProp( options, 'url' ) ) {\n\t\topts.url = options.url;\n\t\tif ( !isString( opts.url ) ) {\n\t\t\treturn new TypeError( 'invalid option. `url` option must be a string primitive. Option: `' + opts.url + '`.' );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'message' ) ) {\n\t\topts.message = options.message;\n\t\tif ( !isString( opts.message ) ) {\n\t\t\treturn new TypeError( 'invalid option. `message` option must be a string primitive. Option: `' + opts.message + '`.' );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\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* Test if a value is a plain object.\n*\n* @module @stdlib/assert-is-plain-object\n*\n* @example\n* var isPlainObject = require( '@stdlib/assert-is-plain-object' );\n*\n* var bool = isPlainObject( {} );\n* // returns true\n*\n* bool = isPlainObject( null );\n* // returns false\n*/\n\n// MODULES //\n\nvar isPlainObject = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = isPlainObject;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar replace = require( '@stdlib/string-replace' );\nvar copy = require( '@stdlib/utils-copy' );\nvar validate = require( './validate.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Returns a function which formats an error message for production.\n*\n* @param {Options} options - function options\n* @param {string} [options.url] - website URL for full error message\n* @param {string} [options.message] - error message template with `{{url}}` and `{{code}}` placeholders that will be replaced\n* @returns {Function} error formatting function\n*\n* @example\n* var opts = {\n* 'url': 'https://stdlib.io/error-decoder.html'\n* };\n*\n* var fcn = factory( opts );\n* // returns \n*/\nfunction factory( options ) {\n\tvar opts;\n\tvar err;\n\topts = copy( defaults );\n\terr = validate( opts, options );\n\tif ( err ) {\n\t\tthrow err;\n\t}\n\treturn formatProdErrorMessage;\n\n\t/**\n\t* Formats an error message for production.\n\t*\n\t* @private\n\t* @param {string} code - error code\n\t* @param {*} ...args - error message arguments\n\t* @returns {string} formatted error message\n\t*/\n\tfunction formatProdErrorMessage() {\n\t\tvar code = arguments[ 0 ];\n\t\tvar url = opts.url + '?code='+code;\n\t\tvar msg;\n\t\tvar i;\n\t\tfor ( i = 1; i < arguments.length; i++ ) {\n\t\t\turl += '&arg[]=' + encodeURIComponent( arguments[ i ] );\n\t\t}\n\t\tmsg = replace( opts.message, '{{url}}', url );\n\t\tmsg = replace( msg, '{{code}}', code );\n\t\treturn msg;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Format an error message for production.\n*\n* @module @stdlib/error-tools-fmtprodmsg\n*\n* @example\n* var formatProdErrorMessage = require( '@stdlib/error-tools-fmtprodmsg' );\n*\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar formatProdErrorMessage = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( formatProdErrorMessage, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\nvar defaults = require( './defaults.json' );\n\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @name formatProdErrorMessage\n* @type {Function}\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = formatProdErrorMessage( '3', 'wrong_type' );\n* // returns \n*/\nvar formatProdErrorMessage = factory( defaults );\n\n\n// EXPORTS //\n\nmodule.exports = formatProdErrorMessage;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["defineProperty","Object","has_define_property_support","err","builtin","objectProtoype","prototype","toStr","toString","defineGetter","__defineGetter__","defineSetter","__defineSetter__","lookupGetter","__lookupGetter__","lookupSetter","__lookupSetter__","polyfill","obj","prop","descriptor","hasValue","hasGet","hasSet","call","TypeError","__proto__","value","Error","get","set","require$$1","require$$2","lib","require$$0","main","configurable","enumerable","writable","primitive","FLG","Symbol","hasSymbols","toStringTag","tostring","native_class","v","has","hasOwnProperty","property","toStrTag","hasOwnProp","isOwn","tag","out","valueOf","String","nativeClass","test","object","isPrimitive","isObject","setReadOnly","isString","require$$3","RE_CHARS","str","s","i","length","replace","substring","re","Boolean","isBoolean","codegen","Function","self_1","self","window_1","window","global","module","exports","getThis","Self","Win","Global","arguments","root","nodeList","document","childNodes","typedarray","Int8Array","RE","check_1","reFunctionName","Array","isArray","isObjectLike","predicate","len","arrayfun","_isBuffer","constructor","isBuffer","REGEXP","match","name","ctor","slice","exec","ctorName","typeOf","type","toLowerCase","RegExp","rescape","isFunction","isRegExp","search","newval","Number","isNumber","POSITIVE_INFINITY","NEGATIVE_INFINITY","floor","Math","x","PINF","NINF","isInt","integer","isInteger","isNonNegativeInteger","getProto","getPrototypeOf","proto","reRegExp","isNan","isnan","isCollection","index_of","arr","searchElement","fromIndex","keys","has_arguments_bug","has_builtin","bool","isArguments","bool$8","detect","detect_1","native","propertyIsEnumerable","bool$7","isEnum","hasStringEnumBug","isEnumerableProperty","require$$4","builtin_wrapper","has_enumerable_prototype_bug","has_non_enumerable_properties_bug","is_constructor_prototype","w","indexOf","isConstructorPrototype","EXCLUDED_KEYS","win","bool$4","k","check","hasAutomationEqualityBug","HAS_WINDOW","HAS_ENUM_PROTO_BUG","HAS_NON_ENUM_PROPS_BUG","error","NON_ENUMERABLE","wrapper","skipConstructor","skipPrototype","isFcn","p","push","getOwnPropertyNames","propertyNames","getOwnPropertyDescriptor","propertyDescriptor","desc","Buffer","GlobalBuffer","b","from","buffer","hasInt8Array","isInt8Array","GlobalInt8Array","INT8_MAX","hasUint8Array","Uint8Array","isUint8Array","GlobalUint8Array","UINT8_MAX","hasUint8ClampedArray","Uint8ClampedArray","isUint8ClampedArray","GlobalUint8ClampedArray","hasInt16Array","Int16Array","isInt16Array","GlobalInt16Array","INT16_MAX","hasUint16Array","Uint16Array","isUint16Array","GlobalUint16Array","UINT16_MAX","hasInt32Array","Int32Array","isInt32Array","GlobalInt32Array","INT32_MAX","hasUint32Array","Uint32Array","isUint32Array","GlobalUint32Array","UINT32_MAX","hasFloat32Array","Float32Array","isFloat32Array","GlobalFloat32Array","hasFloat64Array","Float64Array","isFloat64Array","GlobalFloat64Array","NaN","require$$5","require$$6","require$$7","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","isError","regexp","objectKeys","require$$8","require$$9","require$$10","require$$11","copyBuffer","require$$12","typedArrays","deepCopy","val","copy","cache","refs","level","parent","key","ref","j","tmp","message","stack","code","errno","syscall","copyError","Date","Set","Map","freeze","names","create","isExtensible","preventExtensions","isSealed","seal","isFrozen","cloneInstance","copy_1","objectPrototype","isPrototypeOf","ownProps","validate","opts","options","url","defaults","factory_1","msg","encodeURIComponent","formatProdErrorMessage","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","RangeError","format"],"mappings":";6kBAsBA,ICAIA,EDA0C,mBAA1BC,OAAOD,eAAkCC,OAAOD,eAAiB,KC4BrF,IAAAE,EAbA,WAEC,IAEC,OADAF,EAAgB,GAAI,IAAK,KAClB,EACN,MAAQG,GACT,OAAO,ICiBTC,EALqBH,OAAOD,eC/BxBK,EAAiBJ,OAAOK,UACxBC,EAAQF,EAAeG,SACvBC,EAAeJ,EAAeK,iBAC9BC,EAAeN,EAAeO,iBAC9BC,EAAeR,EAAeS,iBAC9BC,EAAeV,EAAeW,iBAuFlC,IAAAC,EAnDA,SAAyBC,EAAKC,EAAMC,GACnC,IAAId,EACAe,EACAC,EACAC,EAEJ,GAAoB,iBAARL,GAA4B,OAARA,GAAsC,mBAAtBX,EAAMiB,KAAMN,GAC3D,MAAM,IAAIO,UAAW,+DAAiEP,EAAM,MAE7F,GAA2B,iBAAfE,GAA0C,OAAfA,GAAoD,mBAA7Bb,EAAMiB,KAAMJ,GACzE,MAAM,IAAIK,UAAW,oEAAsEL,EAAa,MAyBzG,IAvBAC,EAAa,UAAWD,KAGtBP,EAAaW,KAAMN,EAAKC,IACxBJ,EAAaS,KAAMN,EAAKC,IAGxBb,EAAYY,EAAIQ,UAChBR,EAAIQ,UAAYrB,SAGTa,EAAKC,GACZD,EAAKC,GAASC,EAAWO,MAGzBT,EAAIQ,UAAYpB,GAEhBY,EAAKC,GAASC,EAAWO,OAG3BL,EAAW,QAASF,EACpBG,EAAW,QAASH,EAEfC,IAAcC,GAAUC,GAC5B,MAAM,IAAIK,MAAO,wHASlB,OANKN,GAAUb,GACdA,EAAae,KAAMN,EAAKC,EAAMC,EAAWS,KAErCN,GAAUZ,GACdA,EAAaa,KAAMN,EAAKC,EAAMC,EAAWU,KAEnCZ,GCrEJd,EAAU2B,EACVd,EAAWe,EAefC,EAjB+BC,IASb9B,EAEAa,EC7BdjB,EAAiBkC,EAmCrB,IAAAC,EAZA,SAAmCjB,EAAKC,EAAMQ,GAC7C3B,EAAgBkB,EAAKC,EAAM,CAC1BiB,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,KCJXM,EAL+BC,ECA/B,IAAAK,EAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCMjB,ICdIa,EDIJ,WACC,MACmB,mBAAXC,QACoB,iBAApBA,OAAQ,OCPPC,GAqBV,ICTAT,EDEA,WACC,OAASO,GAAqC,iBAAvBC,OAAOE,aEf/BC,EALY3C,OAAOK,UAAUE,SCAzBD,EAAQ2B,EAiCZ,IAAAW,EAPA,SAAsBC,GACrB,OAAOvC,EAAMiB,KAAMsB,IC3BhBC,EAAM9C,OAAOK,UAAU0C,eAyC3B,ICjBAf,EDIA,SAAqBN,EAAOsB,GAC3B,OACCtB,SAKMoB,EAAIvB,KAAMG,EAAOsB,IEnCrBC,EAA+B,mBAAXT,OAA0BA,OAAOE,YAAc,GCAnEQ,EAAajB,EACbS,EDIaO,ECHb3C,EAAQyB,EAwDZ,ICpCI5B,EAAU2B,EACVd,EDKJ,SAAsB6B,GACrB,IAAIM,EACAC,EACAC,EAEJ,GAAKR,QACJ,OAAOvC,EAAMiB,KAAMsB,GAEpBO,EAAMP,EAAGH,GACTS,EAAQD,EAAYL,EAAGH,GAGvB,IACCG,EAAGH,QAAgB,EAClB,MAAQxC,GACT,OAAOI,EAAMiB,KAAMsB,GASpB,OAPAQ,EAAM/C,EAAMiB,KAAMsB,GAEbM,EACJN,EAAGH,GAAgBU,SAEZP,EAAGH,GAEJW,GCdRrB,EAjBqBC,IASNjB,EAEAb,EChCXmD,ECDUC,OAAOlD,UAAUiD,QDyB/B,IEvBIE,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADA4B,EAAQ/B,KAAMG,IACP,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiB6B,SAGjBhB,EACGkB,EAAM/B,GAEoB,oBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,EAAW9B,EA0Bf,ICSI+B,EAAc5B,EACd6B,EDjBJ,SAAmBpC,GAClB,OAASiC,EAAajC,IAAWkC,EAAUlC,ICkBxCkC,EAAWG,EAKfF,EAAaC,EAAU,cANL/B,GAOlB8B,EAAaC,EAAU,WAAYF,GAKnC,IAAA5B,EAAiB8B,EClDbA,EAAW7B,EAAsC0B,YAKjDK,EAAW,yBAqDf,ICzCAhC,EDIA,SAAkBiC,GACjB,IACIC,EACAC,EAEJ,IAAML,EAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAGrG,GAAkB,MAAbA,EAAK,GAGT,IAAME,EADAF,EAAIG,OACI,EAAGD,GAAK,GACH,MAAbF,EAAKE,GADcA,KAO1B,YAAW,IAANA,GAAgBA,GAAK,EAClBF,EAAII,QAASL,EAAU,SAM/BE,GAHAA,EAAID,EAAIK,UAAW,EAAGH,IAGhBE,QAASL,EAAU,QAGzBC,EAAMA,EAAK,GAAMC,EAAID,EAAIK,UAAWH,KE/CrCI,EALS,ICyBT,IAAAjC,EAPA,SAAoBZ,GACnB,MAA0B,kBAAVA,GCjBbnB,ECDWiE,QAAQnE,UAAUE,SDyBjC,IEvBIiD,EAAc1B,EACd2B,EFUJ,SAAe/B,GACd,IAEC,OADAnB,EAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IEVLqC,EAPiBN,IA0CrB,IAAAyB,EAhBA,SAAoBhC,GACnB,MAAsB,iBAAVA,IACNA,aAAiB8C,UAGjBjC,EACGkB,EAAM/B,GAEoB,qBAAzB8B,EAAa9B,MClCpBiC,EAAc1B,EACd2B,GAAW9B,EAkCf,ICAI+B,GAAc5B,EACdwC,GDRJ,SAAoB/C,GACnB,OAASiC,EAAajC,IAAWkC,GAAUlC,ICSxCkC,GAAWG,EAKfF,GAAaY,GAAW,cANN1C,GAOlB8B,GAAaY,GAAW,WAAYb,IAKpC,IAAA5B,GAAiByC,GCpCjB,IAAAC,GAPA,WACC,OAAO,IAAIC,SAAU,eAAd,ICFRC,GAL4B,iBAATC,KAAsBA,KAAO,KCKhDC,GAL8B,iBAAXC,OAAwBA,OAAS,6GCAhD9D,GAA0B,iBAAX+D,GAAwBA,GAAS,KAKpDC,OAAOC,QAAUjE,OCLbwD,GAAYxC,GAAuC0B,YACnDwB,GAAUrD,GACVsD,GAAOrD,GACPsD,GAAMtB,GACNuB,sCAkDJ,IAAApD,GA7BA,SAAoBwC,GACnB,GAAKa,UAAUnB,OAAS,CACvB,IAAMK,GAAWC,GAChB,MAAM,IAAIlD,UAAW,+DAA+DkD,EAAQ,MAE7F,GAAKA,EACJ,OAAOS,KAKT,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,GAAKC,GACJ,OAAOA,GAGR,MAAM,IAAI3D,MAAO,uDC3Cd6D,GCOYvD,KDNZwD,GAAWD,GAAKE,UAAYF,GAAKE,SAASC,WER1CC,GAAaC,UCEbC,GAAK7D,EACLwD,GHUaA,GGTbG,GDCaA,GC6BjB,IAAAG,GAnBA,WACC,MAEe,mBAAPD,IAGe,iBAAfF,IAGa,mBAAbH,ICST,IAAAvD,GAPA,WACC,MAAO,2BCEJ8D,GAAiBlE,GADHG,EAOL+D,GAAgB,SCjCR/D,MDsCrB,IAAAD,GAAiBgE,GEtCbxC,GAAcvB,EAwClB,ICpBAD,GDWKiE,MAAMC,QACND,MAAMC,QARX,SAAkBxE,GACjB,MAAkC,mBAAzB8B,GAAa9B,IEzBnBwE,GAAUjE,GC0Bd,ICGIkE,GDbJ,SAAuBzE,GACtB,OACW,OAAVA,GACiB,iBAAVA,GCQSO,EAOLkE,GAAc,oBFR3B,SAAmBC,GAClB,GAA0B,mBAAdA,EACX,MAAM,IAAI5E,UAAW,sDAAwD4E,EAAY,MAE1F,OASA,SAAgB1E,GACf,IAAI2E,EACAlC,EACJ,IAAM+B,GAASxE,GACd,OAAO,EAGR,GAAa,KADb2E,EAAM3E,EAAM0C,QAEX,OAAO,EAER,IAAMD,EAAI,EAAGA,EAAIkC,EAAKlC,IACrB,IAAiC,IAA5BiC,EAAW1E,EAAOyC,IACtB,OAAO,EAGT,OAAO,GEpBuCmC,CAAUH,KAK1D,IAAAnE,GAAiBmE,GCvCbA,GAAelE,GA+CnB,IC3BAD,GDOA,SAAmBN,GAClB,OACCyE,GAAczE,KAGbA,EAAM6E,WAEL7E,EAAM8E,aAGgC,mBAA/B9E,EAAM8E,YAAYC,UACzB/E,EAAM8E,YAAYC,SAAU/E,KEtC5B8B,GAAcvB,EACd6D,GAAKhE,GAA0C4E,OAC/CD,GAAW1E,GAuDf,IAAAG,GAxBA,SAA0BW,GACzB,IAAI8D,EACAC,EACAC,EAEJ,IAAe,YADfD,EAAOpD,GAAaX,GAAIiE,MAAO,GAAI,KACC,UAATF,IAAqB/D,EAAE2D,YAAc,CAE/D,GAA0B,iBAD1BK,EAAOhE,EAAE2D,aACQI,KAChB,OAAOC,EAAKD,KAGb,GADAD,EAAQb,GAAGiB,KAAMF,EAAKtG,YAErB,OAAOoG,EAAO,GAGhB,OAAKF,GAAU5D,GACP,SAED+D,GCnDJI,GCkBkB/E,GDmCtB,IErDI+E,GDkBkB/E,GCAtB,ICFIgF,GHkBJ,SAAiBpE,GAChB,IAAIqE,EAGJ,OAAW,OAANrE,EACG,OAKM,YAHdqE,SAAcrE,GAINmE,GAAUnE,GAAIsE,cAEfD,GG9BJlG,GDNJ,SAAiB6B,GAChB,OAAOmE,GAAUnE,GAAIsE,eCetBnF,GAZkBC,KAOajB,GAAWiG,GCtBtCA,GAAShF,GA2Bb,ICNAD,GDFA,SAAqBN,GAEpB,MAA6B,aAApBuF,GAAQvF,IErBdqF,GCFOK,OAAO/G,UAAU0G,KD0B5B,IEvBIvD,GAAc1B,EACd2B,GFUJ,SAAe/B,GACd,IAEC,OADAqF,GAAKxF,KAAMG,IACJ,EACN,MAAQxB,GACT,OAAO,IEVLqC,GAPiBN,IA0CrB,IC1CIoF,GAAUpF,EACVqF,GAAaxF,GACbgC,GAAW/B,EAAsC4B,YACjD4D,GDuBJ,SAAmB7F,GAClB,MAAsB,iBAAVA,IACNA,aAAiB0F,SAGjB7E,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MC2BxB,ICvCAM,GDmBA,SAAkBiC,EAAKuD,EAAQC,GAC9B,IAAM3D,GAAUG,GACf,MAAM,IAAIzC,UAAW,wEAA0EyC,EAAM,MAEtG,GAAKH,GAAU0D,GACdA,EAASH,GAASG,GAClBA,EAAS,IAAIJ,OAAQI,EAAQ,UAEzB,IAAMD,GAAUC,GACpB,MAAM,IAAIhG,UAAW,+FAAiGgG,EAAS,MAEhI,IAAM1D,GAAU2D,KAAaH,GAAYG,GACxC,MAAM,IAAIjG,UAAW,gGAAkGiG,EAAS,MAEjI,OAAOxD,EAAII,QAASmD,EAAQC,IEhC7B,IAAAnF,GAPA,SAAmBZ,GAClB,MAA0B,iBAAVA,GCAjBM,GCjBiB0F,OCAbnH,GCAS0B,GAMS5B,UAAUE,SDkBhC,IEvBIiD,GAAc1B,EACd4F,GAAS3F,GACT0B,GFSJ,SAAe/B,GACd,IAEC,OADAnB,GAASgB,KAAMG,IACR,EACN,MAAQxB,GACT,OAAO,IETLqC,GARiBN,IA2CrB,IAAAyB,GAhBA,SAAmBhC,GAClB,MAAsB,iBAAVA,IACNA,aAAiBgG,KAGjBnF,GACGkB,GAAM/B,GAEoB,oBAAzB8B,GAAa9B,MCnCpBiC,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd0F,GDfJ,SAAmBjG,GAClB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa8D,GAAU,cANL5F,IAOlB8B,GAAa8D,GAAU,WAAY/D,IAKnC,IAAA5B,GAAiB2F,GCvBjB3F,GALmB0F,OAAOE,kBCS1B5F,GA1BaC,GAqBa4F,kBChCtBC,GCsBQC,KAAKD,MDIjB,IENA9F,GFDA,SAAoBgG,GACnB,OAAQF,GAAME,KAAOA,GGpBlBC,GAAOhG,GACPiG,GAAOpG,GACPqG,GAAQpG,GAuBZ,IAAAqG,GAXA,SAAoB1G,GACnB,OACCA,EAAQuG,IACRvG,EAAQwG,IACRC,GAAOzG,IClBLiG,GAAW1F,GAAsC0B,YACjDwE,GAAQrG,GA6BZ,IAAAQ,GAVA,SAAoBZ,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,ICvBLiG,GAAW1F,GAAsC2B,SACjDuE,GAAQrG,GA6BZ,IAAA4B,GAVA,SAAoBhC,GACnB,OACCiG,GAAUjG,IACVyG,GAAOzG,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICMI+B,GAAc5B,EACdoG,GDdJ,SAAoB3G,GACnB,OAASiC,GAAajC,IAAWkC,GAAUlC,ICexCkC,GAAWG,GAKfF,GAAawE,GAAW,cANNtG,IAOlB8B,GAAawE,GAAW,WAAYzE,IAKpC,IAAA5B,GAAiBqG,GCvDbA,GAAYpG,GAAuC0B,YA6BvD,IAAArB,GAVA,SAA+BZ,GAC9B,OACC2G,GAAW3G,IACXA,GAAS,GCtBP2G,GAAYpG,GAAuC2B,SA6BvD,IAAAF,GAVA,SAA+BhC,GAC9B,OACC2G,GAAW3G,IACXA,EAAM4B,WAAa,GCtBjBK,GAAc1B,GACd2B,GAAW9B,GAsCf,ICGI+B,GAAc5B,EACdqG,GDXJ,SAA+B5G,GAC9B,OAASiC,GAAajC,IAAWkC,GAAUlC,ICYxCkC,GAAWG,GAKfF,GAAayE,GAAsB,cANjBvG,IAOlB8B,GAAayE,GAAsB,WAAY1E,IAK/C,IAAA5B,GAAiBsG,GCxDbC,GAAWvI,OAAOwI,eCatB,IAAAC,GARA,SAAmBxH,GAElB,OAAOA,EAAIQ,WCPR+B,GAAcvB,EACdsG,GAAWzG,GA+Bf,IAAAd,GAnBA,SAAyBC,GACxB,IAAIwH,EAAQF,GAAUtH,GACtB,OAAKwH,GAAmB,OAAVA,EACNA,EAEgC,sBAAnCjF,GAAavC,EAAIuF,aAEdvF,EAAIuF,YAAYnG,UAEnBY,aAAejB,OACZA,OAAOK,UAGR,MCzBJF,GHIaoI,GGHbvH,GAAWe,GCFXwG,GDAatG,GAQAjC,OAAOwI,gBACZrI,GAEAa,GCoBZ,ICdAgB,GDFA,SAAyBN,GACxB,OACCA,QAGO,MAGRA,EAAQ1B,OAAQ0B,GAET6G,GAAU7G,KEzBd8G,GAAiBvG,GACjBuB,GAAc1B,EAwClB,ICrBAE,GDAA,SAAkBN,GACjB,GAAsB,iBAAVA,GAAgC,OAAVA,EACjC,OAAO,EAGR,GAAKA,aAAiBC,MACrB,OAAO,EAGR,KAAQD,GAAQ,CACf,GAA8B,mBAAzB8B,GAAa9B,GACjB,OAAO,EAERA,EAAQ8G,GAAgB9G,GAEzB,OAAO,GEdR,IAAAQ,GAPA,WACC,MAAO,oCCWJwG,GAAW5G,GADGG,EAOLyG,GAAU,SChCRzG,UCAX6B,GAAW7B,EAAsC0B,YACjD+E,GFyCaA,GEXjB,ICdA1G,GDAA,SAAuBiC,GACtB,IAAMH,GAAUG,GACf,MAAM,IAAIzC,UAAW,uEAAyEyC,EAAM,MAMrG,OAHAA,EAAMyE,KAAW3B,KAAM9C,IAGN,IAAImD,OAAQnD,EAAI,GAAIA,EAAI,IAAO,MEJjD,IAAA/B,GAPA,SAAgB8F,GACf,OAASA,GAAMA,GCfZL,GAAW1F,GAAsC0B,YACjDgF,GCcQ1G,GDmBZ,IAAAK,GAVA,SAAgBZ,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,IE3BLiG,GAAW1F,GAAsC2B,SACjD+E,GDcQ1G,GCeZ,IAAAyB,GAVA,SAAgBhC,GACf,OACCiG,GAAUjG,IACViH,GAAOjH,EAAM4B,YCvBXK,GAAc1B,GACd2B,GAAW9B,GAkCf,ICOI+B,GAAc5B,EACd2G,GDfJ,SAAgBlH,GACf,OAASiC,GAAajC,IAAWkC,GAAUlC,ICgBxCkC,GAAWG,GAKfF,GAAa+E,GAAO,cANF7G,IAOlB8B,GAAa+E,GAAO,WAAYhF,IAKhC,IAAA5B,GAAiB4G,GCxDbP,GAAYpG,GAkChB,IClCI2G,GAAQ3G,GACR4G,GDmBJ,SAAuBnH,GACtB,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QENqB,kBDnBzBN,GAAW/B,EAAsC4B,YACjD0E,GAAYtE,GAAuCJ,YA0GvD,IAAAmF,GAhDA,SAAkBC,EAAKC,EAAeC,GACrC,IAAI5C,EACAlC,EACJ,IAAM0E,GAAcE,KAAUjF,GAAUiF,GACvC,MAAM,IAAIvH,UAAW,0EAA4EuH,EAAM,MAGxG,GAAa,KADb1C,EAAM0C,EAAI3E,QAET,OAAQ,EAET,GAA0B,IAArBmB,UAAUnB,OAAe,CAC7B,IAAMiE,GAAWY,GAChB,MAAM,IAAIzH,UAAW,6DAA+DyH,EAAY,MAEjG,GAAKA,GAAa,EAAI,CACrB,GAAKA,GAAa5C,EACjB,OAAQ,EAETlC,EAAI8E,OAEJ9E,EAAIkC,EAAM4C,GACD,IACR9E,EAAI,QAINA,EAAI,EAGL,GAAKyE,GAAOI,IACX,KAAQ7E,EAAIkC,EAAKlC,IAChB,GAAKyE,GAAOG,EAAI5E,IACf,OAAOA,OAIT,KAAQA,EAAIkC,EAAKlC,IAChB,GAAK4E,EAAK5E,KAAQ6E,EACjB,OAAO7E,EAIV,OAAQ,GErDTnC,GALcC,GClBd,IAAA9B,GAPA,SAAeuB,GACd,OAAO1B,OAAOkJ,KAAMlJ,OAAQ0B,KCrBzBwH,GAAOjH,GAmCX,IAAAkH,GAPA,WACC,OAlBD,WACC,OAA8C,KAArCD,GAAM3D,YAAe,IAAKnB,OAiB5BX,CAAM,EAAG,ICxBjB2F,QALoC,IAAhBpJ,OAAOkJ,KCAvB1F,GAAcvB,EA+BlB,IC1BIoH,GD0BJnH,GAPA,SAAsBR,GACrB,MAAkC,uBAAzB8B,GAAa9B,ICzBnB4H,GAAcrH,GA2BdsH,GAPJ,WACC,OAAOD,GAAa/D,WAMdiE,GAKP,IC3BIH,GD2BJI,GAAiBJ,GEDjBK,GAL2B1J,OAAOK,UAAUsJ,qBDHxCC,IAvBS3H,GAiBGV,KAAM,OAAQ,KAW9B,IE5BIuC,GAAW7B,EACX2G,GAAQ9G,GAAmC6B,YAC3C0E,GAAYtG,GAAuC4B,YACnDkG,GAAS9F,GACT+F,GFwBaT,GE6BjB,IAAAnH,GAzBA,SAA+BR,EAAOsB,GACrC,IAAIqG,EACJ,OACC3H,YAKD2H,EAAOQ,GAAOtI,KAAMG,EAAOsB,KACb8G,IAAoBhG,GAAUpC,IAIzCkH,GAFF5F,GAAYA,IAGXqF,GAAWrF,IACXA,GAAY,GACZA,EAAWtB,EAAM0C,OAGZiF,IC3BRrH,GAL2BC,GCnBvBiB,GAAajB,EACb8H,GAAuBjI,GACvBoE,GAAUnE,GACVsG,GAAYtE,GCiChB,IAAA/B,GAjBwBC,GACbH,GDQX,SAAsBJ,GACrB,OACW,OAAVA,GACiB,iBAAVA,IACNwE,GAASxE,IACc,iBAAjBA,EAAM0C,QACbiE,GAAW3G,EAAM0C,SACjB1C,EAAM0C,QAAU,GAChB1C,EAAM0C,QAhCS4F,YAiCf9G,GAAYxB,EAAO,YAClBqI,GAAsBrI,EAAO,WEtC5B4H,GAAcrH,GACd9B,GAAU2B,GAKVgF,GAAQb,MAAM5F,UAAUyG,MA+B5B,IAAAmD,GAVA,SAAevI,GACd,OAAK4H,GAAa5H,GACVvB,GAAS2G,GAAMvF,KAAMG,IAEtBvB,GAASuB,ICnBjB,ICAAwI,GAZ2BjI,IDK3B,cCEuC,aCWvCkI,IAlB2BlI,GAKjB,CACT1B,SAAY,MAO0B,YCCvC,ICJI8I,GDIJe,GAPA,SAAiC1I,GAChC,OAASA,EAAM8E,aAAe9E,EAAM8E,YAAYnG,YAAcqB,GER3D2I,GAAwB,oBAAXtF,YAA2B,EAASA,ODAjD7B,GAAajB,EACbqI,GAAUxI,GACVmF,GAASlF,GACTwI,GAAyBxG,GACzByG,wPACAC,GCAaJ,GD2CbK,GAzBJ,WACC,IAAIC,EACJ,GAAuB,cAAlB1D,GAAQwD,IACZ,OAAO,EAER,IAAME,KAAKF,GACV,KAEmC,IAAjCH,GAASE,GAAeG,IACxBzH,GAAYuH,GAAKE,IACJ,OAAbF,GAAKE,IACkB,WAAvB1D,GAAQwD,GAAKE,KAEbJ,GAAwBE,GAAKE,IAE7B,MAAQzK,GACT,OAAO,EAGT,OAAO,EAMD0K,GAKP,IErDIvB,GAA2B,oBAAXtE,OCAhB8F,GHqDaxB,GGpDbkB,GAAyBzI,GACzBgJ,GDGazB,GCuBjB,IC5BIlD,GAAelE,GACfiB,GAAapB,EACbwH,GAAcvH,GACdgJ,GAAqBhH,GACrBiH,GAAyBhB,GACzBO,GDSJ,SAAkB7I,GACjB,IAAoB,IAAfoJ,KAAyBD,GAC7B,OAAON,GAAwB7I,GAEhC,IACC,OAAO6I,GAAwB7I,GAC9B,MAAQuJ,GACT,OAAO,ICfLC,iHAyEJ,IC7EI/K,GAAU4B,GACVoJ,GAAUpH,GACV/C,GDuBJ,SAAeU,GACd,IAAI0J,EACAC,EACAC,EACAjI,EACAsH,EACAY,EACApH,EAGJ,GADAd,EAAM,GACDiG,GAAa5H,GAAU,CAE3B,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,YAGb,OAAO8C,EAER,GAAsB,iBAAV3B,GAEX,GAAKA,EAAM0C,OAAS,IAAMlB,GAAYxB,EAAO,KAC5C,IAAMyC,EAAI,EAAGA,EAAIzC,EAAM0C,OAAQD,IAC9Bd,EAAImI,KAAMrH,EAAE5D,gBAGR,CAEN,IAAe,KADf+K,EAA2B,mBAAV5J,KACQyE,GAAczE,GACtC,OAAO2B,EAERgI,EAAkBN,IAAsBO,EAEzC,IAAMX,KAAKjJ,EACF2J,GAAuB,cAANV,IAAuBzH,GAAYxB,EAAOiJ,IAClEtH,EAAImI,KAAMjI,OAAQoH,IAGpB,GAAKK,GAEJ,IADAI,EAAkBb,GAAwB7I,GACpCyC,EAAI,EAAGA,EAAI+G,GAAe9G,OAAQD,IACvCoH,EAAIL,GAAgB/G,GACZiH,GAAyB,gBAANG,IAAyBrI,GAAYxB,EAAO6J,IACtElI,EAAImI,KAAMjI,OAAQgI,IAIrB,OAAOlI,GEnDRrB,GDrBkBF,GADIG,KA6BbkJ,GAEAhL,GAGDa,GE7BRoI,QALmD,IAA/BpJ,OAAOyL,oBCAvBC,GAAgB1L,OAAOyL,oBAgC3B,IChCIvC,GAAOjH,GCgCX,IAAAD,GAjBkBC,GFUlB,SAA8BP,GAC7B,OAAOgK,GAAe1L,OAAQ0B,KCA/B,SAA8BA,GAC7B,OAAOwH,GAAMlJ,OAAQ0B,KEtBtB0H,QALwD,IAApCpJ,OAAO2L,yBCAvBC,GAAqB5L,OAAO2L,yBAuChC,ICvCIzI,GAAajB,ECkCjB,IAAAD,GAjBkBC,GFUlB,SAAmCP,EAAOsB,GACzC,IAAI6I,EACJ,OAAKnK,cAIa,KADlBmK,EAAOD,GAAoBlK,EAAOsB,IAF1B,KAG4B6I,GCLrC,SAAmCnK,EAAOsB,GACzC,OAAKE,GAAYxB,EAAOsB,GAChB,CACNb,cAAgB,EAChBC,YAAc,EACdC,UAAY,EACZX,MAASA,EAAOsB,IAGX,o4qBErCJd,GAA0C4J,GAK9C7G,OAAOC,QAAUhD,OCLbuE,GAAWxE,GACX8J,sCA4CJ,IAAA7J,GA9BA,WACC,IAAImH,EACA2C,EAEJ,GAA6B,mBAAjBD,GACX,OAAO,EAGR,IAEEC,EADiC,mBAAtBD,GAAaE,KACpBF,GAAaE,KAAM,CAAE,EAAG,EAAG,EAAG,IAE9B,IAAIF,GAAc,CAAE,EAAG,EAAG,EAAG,IAElC1C,EACC5C,GAAUuF,IACC,IAAXA,EAAG,IACQ,IAAXA,EAAG,IACQ,IAAXA,EAAG,IACQ,IAAXA,EAAG,GAEH,MAAQ9L,GACTmJ,GAAO,EAER,OAAOA,GCtBRrH,GAL2BC,GCE3B,ICDIC,SCb2B4J,ODc3B9K,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GAjB2BC,KASnBC,GAEAlB,GEjBJqI,GANapH,GACJH,GAKiBmK,MCN1BxF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAI,GAVA,SAAqBgK,GACpB,IAAMzF,GAAUyF,GACf,MAAM,IAAI1K,UAAW,oDAAsD0K,EAAS,KAErF,OAAOJ,GAAOG,KAAMC,IC1BjBzF,GAAWxE,GACX6J,GAAShK,GA+Bb,IAAAd,GAVA,SAAqBkL,GACpB,IAAMzF,GAAUyF,GACf,MAAM,IAAI1K,UAAW,oDAAsD0K,EAAS,KAErF,OAAO,IAAIJ,GAAQI,ICOpBlK,GHtBiBqH,GGMNvH,GACIC,GClBXyB,GAAcvB,EAKdkK,GAAsC,mBAAdtG,UA6B5B,IClCI3D,GAA8B,mBAAd2D,UAA6BA,UAAY,KCAzDuG,GFwBJ,SAAsB1K,GACrB,OACGyK,IAAgBzK,aAAiBmE,WACV,uBAAzBrC,GAAa9B,IExBX2K,GDEanK,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAgC,mBAApBsD,GACX,OAAO,EAGR,IACCtD,EAAM,IAAIsD,GAAiB,CAAE,EAAG,MAAO,KAAMC,MAC7CjD,EACC+C,GAAarD,IACA,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEO,MDDZA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb8B,mBAAd0F,UAA6BA,eAAY,EDczD7E,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB0BC,KFSlB9B,GAEAa,GGvBJwC,GAAcvB,EAKdsK,GAAwC,mBAAfC,WA6B7B,IClCItK,GAA+B,mBAAfsK,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuB/K,GACtB,OACG6K,IAAiB7K,aAAiB8K,YACX,wBAAzBhJ,GAAa9B,IEzBXgL,GDGaxK,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB2D,GACX,OAAO,EAGR,IAEC3D,EAAM,IAAI2D,GADV3D,EAAM,CAAE,EAAG,MAAO,KAAM4D,IAAaA,MAErCtD,EACCoD,GAAc1D,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ4D,MAAb5D,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCb+B,mBAAfqM,WAA8BA,gBAAa,EDc3DxL,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd2K,GAAsD,mBAAtBC,kBA6BpC,IClCI3K,GAAsC,mBAAtB2K,kBAAqCA,kBAAoB,KCAzEC,GFwBJ,SAA8BpL,GAC7B,OACGkL,IAAwBlL,aAAiBmL,mBAClB,+BAAzBrJ,GAAa9B,IE1BXqL,GDIa7K,GCuCjB,IAAAA,GA7BA,WACC,IAAImH,EACAN,EAEJ,GAAwC,mBAA5BgE,GACX,OAAO,EAGR,IACChE,EAAM,IAAIgE,GAAyB,EAAG,EAAG,EAAG,EAAG,KAAM,KAAM,IAAK,MAChE1D,EACCyD,GAAqB/D,IACR,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ,MAAbA,EAAK,IACQ,MAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbsC,mBAAtB0M,kBAAqCA,uBAAoB,EDczE7L,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjBkCC,KFS1B9B,GAEAa,GGvBJwC,GAAcvB,EAKd+K,GAAwC,mBAAfC,WA6B7B,IClCI/K,GAA+B,mBAAf+K,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBxL,GACtB,OACGsL,IAAiBtL,aAAiBuL,YACX,wBAAzBzJ,GAAa9B,IExBXyL,GDEajL,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArBoE,GACX,OAAO,EAGR,IACCpE,EAAM,IAAIoE,GAAkB,CAAE,EAAG,MAAO,KAAMC,QAC9C/D,EACC6D,GAAcnE,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,QDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAf8M,WAA8BA,gBAAa,EDc3DjM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKdoL,GAA0C,mBAAhBC,YA6B9B,IClCIpL,GAAgC,mBAAhBoL,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwB7L,GACvB,OACG2L,IAAkB3L,aAAiB4L,aACZ,yBAAzB9J,GAAa9B,IEzBX8L,GDGatL,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtByE,GACX,OAAO,EAGR,IAECzE,EAAM,IAAIyE,GADVzE,EAAM,CAAE,EAAG,MAAO,KAAM0E,MAAcA,QAEtCpE,EACCkE,GAAexE,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQ0E,QAAb1E,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhBmN,YAA+BA,iBAAc,EDc7DtM,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdyL,GAAwC,mBAAfC,WA6B7B,IClCIzL,GAA+B,mBAAfyL,WAA8BA,WAAa,KCA3DC,GFwBJ,SAAuBlM,GACtB,OACGgM,IAAiBhM,aAAiBiM,YACX,wBAAzBnK,GAAa9B,IExBXmM,GDEa3L,GCsCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAiC,mBAArB8E,GACX,OAAO,EAGR,IACC9E,EAAM,IAAI8E,GAAkB,CAAE,EAAG,MAAO,KAAMC,aAC9CzE,EACCuE,GAAc7E,IACD,IAAbA,EAAK,IACQ,IAAbA,EAAK,KACS,IAAdA,EAAK,KCEQ,aDDbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GEvBR,ICDIlJ,GCb+B,mBAAfwN,WAA8BA,gBAAa,EDc3D3M,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB2BC,KFSnB9B,GAEAa,GGvBJwC,GAAcvB,EAKd8L,GAA0C,mBAAhBC,YA6B9B,IClCI9L,GAAgC,mBAAhB8L,YAA+BA,YAAc,KCA7DC,GFwBJ,SAAwBvM,GACvB,OACGqM,IAAkBrM,aAAiBsM,aACZ,yBAAzBxK,GAAa9B,IEzBXwM,GDGahM,GCuCjB,IAAAA,GA5BA,WACC,IAAImH,EACAN,EAEJ,GAAkC,mBAAtBmF,GACX,OAAO,EAGR,IAECnF,EAAM,IAAImF,GADVnF,EAAM,CAAE,EAAG,MAAO,KAAMoF,WAAcA,aAEtC9E,EACC4E,GAAelF,IACF,IAAbA,EAAK,IACQ,IAAbA,EAAK,IACQoF,aAAbpF,EAAK,IACQ,IAAbA,EAAK,IACQ,IAAbA,EAAK,GAEL,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCxBR,ICDIlJ,GCbgC,mBAAhB6N,YAA+BA,iBAAc,EDc7DhN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB4BC,KFSpB9B,GAEAa,GGvBJwC,GAAcvB,EAKdmM,GAA4C,mBAAjBC,aA6B/B,IClCInM,GAAiC,mBAAjBmM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyB5M,GACxB,OACG0M,IAAmB1M,aAAiB2M,cACb,0BAAzB7K,GAAa9B,IE1BXuG,GAAOnG,GACPyM,GDGarM,GCqCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvBwF,GACX,OAAO,EAGR,IACCxF,EAAM,IAAIwF,GAAoB,CAAE,EAAK,MAAO,KAAM,OAClDlF,EACCiF,GAAgBvF,IACH,IAAbA,EAAK,IACQ,oBAAbA,EAAK,KACS,oBAAdA,EAAK,IACLA,EAAK,KAAQd,GAEb,MAAQ/H,GACTmJ,GAAO,EAER,OAAOA,GCtBR,ICDIlJ,GCbiC,mBAAjBkO,aAAgCA,kBAAe,EDc/DrN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCqBlBK,GEjB6BC,KFSrB9B,GAEAa,GGvBJwC,GAAcvB,EAKduM,GAA4C,mBAAjBC,aA6B/B,IClCIvM,GAAiC,mBAAjBuM,aAAgCA,aAAe,KCA/DC,GFwBJ,SAAyBhN,GACxB,OACG8M,IAAmB9M,aAAiB+M,cACb,0BAAzBjL,GAAa9B,IE1BXiN,GDIazM,GCoCjB,IAAAA,GA1BA,WACC,IAAImH,EACAN,EAEJ,GAAmC,mBAAvB4F,GACX,OAAO,EAGR,IACC5F,EAAM,IAAI4F,GAAoB,CAAE,EAAK,MAAO,KAAMC,MAClDvF,EACCqF,GAAgB3F,IACH,IAAbA,EAAK,IACQ,OAAbA,EAAK,KACS,OAAdA,EAAK,IACLA,EAAK,IAAQA,EAAK,GAElB,MAAQ7I,GACTmJ,GAAO,EAER,OAAOA,GCrBR,ICKIxC,GANA1G,GCbiC,mBAAjBsO,aAAgCA,kBAAe,EDc/DzN,GDPJ,WACC,MAAM,IAAIW,MAAO,oBCajBkF,GET4B5E,KFSrB9B,GAEAa,GAMR,IG7BI6E,GAAY5D,GACZuK,GAAa1K,GACb+K,GAAoB9K,GACpBkL,GAAalJ,GACbuJ,GAActD,GACd2D,GAAakB,GACbb,GAAcc,GACdT,GAAeU,GACfN,GHqBa5H,GGJjB,SAASmI,GAAWjG,GACnB,OAAO,IAAIlD,GAAWkD,GAUvB,SAASkG,GAAYlG,GACpB,OAAO,IAAIyD,GAAYzD,GAUxB,SAASmG,GAAmBnG,GAC3B,OAAO,IAAI8D,GAAmB9D,GAU/B,SAASoG,GAAYpG,GACpB,OAAO,IAAIkE,GAAYlE,GAUxB,SAASqG,GAAarG,GACrB,OAAO,IAAIuE,GAAavE,GAUzB,SAASsG,GAAYtG,GACpB,OAAO,IAAI4E,GAAY5E,GAUxB,SAASuG,GAAavG,GACrB,OAAO,IAAIiF,GAAajF,GAUzB,SAASwG,GAAcxG,GACtB,OAAO,IAAIsF,GAActF,GAU1B,SAASyG,GAAczG,GACtB,OAAO,IAAI0F,GAAc1F,GAgC1B,IClJI7F,GAAajB,EACbiE,GAAUpE,GACV2E,GAAW1E,GACX0N,GAAU1L,GACVkD,GAAS+C,GACT0F,GAASb,GACTvE,GAAUwE,GACVa,GAAaZ,GACbrD,GAAgBkE,GAChBhE,GAAqBiE,GACrBrH,GAAiBsH,GACjB/P,GAAiBgQ,EACjBC,GAAaC,GACbC,GD+GO,CACTlB,UAAaA,GACbC,WAAcA,GACdC,kBAAqBA,GACrBC,WAAcA,GACdC,YAAeA,GACfC,WAAcA,GACdC,YAAeA,GACfC,aAAgBA,GAChBC,aAAgBA,ICQlB,SAASW,GAAUC,EAAKC,EAAMC,EAAOC,EAAMC,GAC1C,IAAIC,EACAvH,EACAtC,EACAiF,EACAhF,EACA6J,EACAC,EACA3I,EACA7D,EACAyM,EAKJ,GAHAJ,GAAS,EAIO,iBAARJ,GACC,OAARA,EAEA,OAAOA,EAER,GAAK3J,GAAU2J,GACd,OAAOJ,GAAYI,GAEpB,GAAKX,GAASW,GACb,OAnFF,SAAoBnF,GACnB,IAEI/B,EACA2C,EACAgF,EACAH,EACAxQ,EACAiE,EAPAmM,EAAQ,GACRC,EAAO,GA8BX,IArBArQ,EAAM,IAAI+K,EAAMzE,YAAayE,EAAM6F,SAEnCR,EAAM9E,KAAMP,GACZsF,EAAK/E,KAAMtL,GAGN+K,EAAM8F,QACV7Q,EAAI6Q,MAAQ9F,EAAM8F,OAGd9F,EAAM+F,OACV9Q,EAAI8Q,KAAO/F,EAAM+F,MAEb/F,EAAMgG,QACV/Q,EAAI+Q,MAAQhG,EAAMgG,OAEdhG,EAAMiG,UACVhR,EAAIgR,QAAUjG,EAAMiG,SAGrBhI,EAAOyG,GAAY1E,GACb9G,EAAI,EAAGA,EAAI+E,EAAK9E,OAAQD,IAC7BuM,EAAMxH,EAAM/E,GACZ0H,EAAOD,GAAoBX,EAAOyF,GAC7BxN,GAAY2I,EAAM,WACtBgF,EAAQ3K,GAAS+E,EAAOyF,IAAY,GAAK,GACzC7E,EAAKnK,MAAQyO,GAAUlF,EAAOyF,GAAOG,EAAKP,EAAOC,GAAO,IAEzDxQ,GAAgBG,EAAKwQ,EAAK7E,GAE3B,OAAO3L,EA0CCiR,CAAWf,GAKnB,GAAc,UAFdxJ,EAAOK,GAAQmJ,IAGd,OAAO,IAAIgB,MAAOhB,GAEnB,GAAc,WAATxJ,EACJ,OAAO8I,GAAQU,EAAI7P,YAEpB,GAAc,QAATqG,EACJ,OAAO,IAAIyK,IAAKjB,GAEjB,GAAc,QAATxJ,EACJ,OAAO,IAAI0K,IAAKlB,GAEjB,GACU,WAATxJ,GACS,YAATA,GACS,WAATA,EAGA,OAAOwJ,EAAI9M,UAGZ,GADAuD,EAAOqJ,GAAatJ,GAEnB,OAAOC,EAAMuJ,GAGd,GACU,UAATxJ,GACS,WAATA,EAGA,MAA8B,mBAAlB5G,OAAOuR,OA1KrB,SAAwBnB,GACvB,IAAIE,EACAkB,EACA5K,EACA2J,EACA1E,EACAgF,EACAF,EACAxM,EAUJ,IARAmM,EAAQ,GACRC,EAAO,GAEPI,EAAM3Q,OAAOyR,OAAQjJ,GAAgB4H,IACrCE,EAAM9E,KAAM4E,GACZG,EAAK/E,KAAMmF,GAEXa,EAAQ9F,GAAe0E,GACjBjM,EAAI,EAAGA,EAAIqN,EAAMpN,OAAQD,IAC9ByC,EAAO4K,EAAOrN,GACd0H,EAAOD,GAAoBwE,EAAKxJ,GAC3B1D,GAAY2I,EAAM,WACtBgF,EAAQ3K,GAASkK,EAAIxJ,IAAY,GAAK,GACtCiF,EAAKnK,MAAQyO,GAAUC,EAAIxJ,GAAOiK,EAAKP,EAAOC,GAAO,IAEtDxQ,GAAgB4Q,EAAK/J,EAAMiF,GAW5B,OATM7L,OAAO0R,aAActB,IAC1BpQ,OAAO2R,kBAAmBhB,GAEtB3Q,OAAO4R,SAAUxB,IACrBpQ,OAAO6R,KAAMlB,GAET3Q,OAAO8R,SAAU1B,IACrBpQ,OAAOuR,OAAQZ,GAETA,EAuIEoB,CAAe3B,GAEhB,GAIR,GADAlH,EAAOyG,GAAYS,GACdI,EAAQ,EAEZ,IADAC,EAAS7J,EACHgK,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAE7B5I,EAAIoI,EADJM,EAAMxH,EAAM0H,IAIZhK,EAAOK,GAAQe,GAED,iBAANA,GACD,OAANA,GAEU,UAATpB,GACS,WAATA,GAEDH,GAAUuB,GAEM,WAAXyI,GACJ5E,EAAOD,GAAoBwE,EAAKM,GAC3BxN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQyO,GAAUnI,IAExBjI,GAAgBsQ,EAAMK,EAAK7E,IAE3BwE,EAAMK,GAAQP,GAAUnI,IAMd,KADZ7D,EAAImG,GAASgG,EAAOtI,KAMpB2I,EAAQzK,GAAS8B,GAAQ,IAAI/B,MAAO+B,EAAE5D,QAAW,GACjDkM,EAAM9E,KAAMxD,GACZuI,EAAK/E,KAAMmF,GACK,UAAXF,EACJJ,EAAMK,GAAQP,GAAUnI,EAAG2I,EAAKL,EAAOC,EAAMC,IAE7C3E,EAAOD,GAAoBwE,EAAKM,GAC3BxN,GAAY2I,EAAM,WACtBA,EAAKnK,MAAQyO,GAAUnI,EAAG2I,EAAKL,EAAOC,EAAMC,IAE7CzQ,GAAgBsQ,EAAMK,EAAK7E,KAd3BwE,EAAMK,GAAQH,EAAMpM,QAiBhB,GAAc,UAATyC,EACX,IAAMgK,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAE7BP,EADAK,EAAMxH,EAAM0H,IACER,EAAKM,QAGpB,IAAME,EAAI,EAAGA,EAAI1H,EAAK9E,OAAQwM,IAC7BF,EAAMxH,EAAM0H,GACZ/E,EAAOD,GAAoBwE,EAAKM,GAChC3Q,GAAgBsQ,EAAMK,EAAK7E,GAY7B,OATM7L,OAAO0R,aAActB,IAC1BpQ,OAAO2R,kBAAmBtB,GAEtBrQ,OAAO4R,SAAUxB,IACrBpQ,OAAO6R,KAAMxB,GAETrQ,OAAO8R,SAAU1B,IACrBpQ,OAAOuR,OAAQlB,GAETA,EAMR,IC3RInK,GAAUjE,GACVqG,GAAuBxG,GAAmD6B,YAC1EsE,GAAOlG,GACPoO,GDwRaA,GCtOjB,IAAA6B,GAnBA,SAAetQ,EAAO8O,GACrB,IAAInN,EACJ,GAAKkC,UAAUnB,OAAS,EAAI,CAC3B,IAAMkE,GAAsBkI,GAC3B,MAAM,IAAIhP,UAAW,oEAAsEgP,EAAQ,MAEpG,GAAe,IAAVA,EACJ,OAAO9O,OAGR8O,EAAQvI,GAGT,OADA5E,EAAQ6C,GAASxE,GAAY,IAAIuE,MAAOvE,EAAM0C,QAAW,GAClD+L,GAAUzO,EAAO2B,EAAK,CAAC3B,GAAQ,CAAC2B,GAAMmN,ICd9CxO,GALWC,GC5BPiE,GAAUjE,GA8Bd,IC9BI2B,GDmBJ,SAAmBlC,GAClB,MACkB,iBAAVA,GACG,OAAVA,IACCwE,GAASxE,ICtBR4F,GAAaxF,GACb0G,GAAiBzG,GACjBmB,GAAaa,EACbP,GAAcwG,EAKdiI,GAAkBjS,OAAOK,UAgF7B,IAAA6B,GAvCA,SAAwBR,GACvB,IAAI+G,EAGJ,QAAM7E,GAAUlC,OAIhB+G,EAAQD,GAAgB9G,MAOtBwB,GAAYxB,EAAO,gBAGpBwB,GAAYuF,EAAO,gBACnBnB,GAAYmB,EAAMjC,cACmB,sBAArChD,GAAaiF,EAAMjC,cAGnBtD,GAAYuF,EAAO,kBACnBnB,GAAYmB,EAAMyJ,iBAIjBzJ,IAAUwJ,IAzDb,SAAmBhR,GAClB,IAAIyP,EAGJ,IAAMA,KAAOzP,EACZ,IAAMiC,GAAYjC,EAAKyP,GACtB,OAAO,EAGT,OAAO,EAmDLyB,CAAUzQ,MCjFTkC,GCegB3B,GDdhBiB,GAAapB,EACbgC,GAAW/B,EAAsC4B,YAqCrD,wJEvCIU,GAAUpC,GACVoO,GAAOvO,GACPsQ,GFeJ,SAAmBC,EAAMC,GACxB,OAAM1O,GAAU0O,GAGXpP,GAAYoP,EAAS,SACzBD,EAAKE,IAAMD,EAAQC,KACbzO,GAAUuO,EAAKE,MACb,IAAI/Q,UAAW,qEAAuE6Q,EAAKE,IAAM,MAGrGrP,GAAYoP,EAAS,aACzBD,EAAKvB,QAAUwB,EAAQxB,SACjBhN,GAAUuO,EAAKvB,UACb,IAAItP,UAAW,yEAA2E6Q,EAAKvB,QAAU,MAG3G,KAdC,IAAItP,UAAW,iEAAmE8Q,EAAU,OEhBjGE,GAAWzO,GAwDf,IAAA0O,GAnCA,SAAkBH,GACjB,IAAID,EACAnS,EAGJ,GAFAmS,EAAOhC,GAAMmC,IACbtS,EAAMkS,GAAUC,EAAMC,GAErB,MAAMpS,EAEP,OAUA,WACC,IAEIwS,EACAvO,EAHA6M,EAAOzL,UAAW,GAClBgN,EAAMF,EAAKE,IAAM,SAASvB,EAG9B,IAAM7M,EAAI,EAAGA,EAAIoB,UAAUnB,OAAQD,IAClCoO,GAAO,UAAYI,mBAAoBpN,UAAWpB,IAInD,OAFAuO,EAAMrO,GAASgO,EAAKvB,QAAS,UAAWyB,GACxCG,EAAMrO,GAASqO,EAAK,WAAY1B,KCtC9B4B,GCbU3Q,GACCH,IDWGG,EAOL2Q,GAAwB,UALvB7Q,IAUd,IAAAC,GAAiB4Q,UEiFjB,WACC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAnP,EACA0M,EACAzM,EASJ,IANA0O,EAAUtN,UAAW,GACrBuN,EAASvN,UAAW,GAGpBwN,GADAG,EAAQ3N,UAAW,GADnB0N,GAHAD,EAAQzN,UAAW,IAGLnB,UAECA,OACfgP,EAAMN,EACA3O,EAAI,EAAGA,EAAI8O,EAAO9O,IAAM,CAI7B,GAHAkP,EAAIL,EAAO7O,GACXyM,EAAIrL,UAAWpB,EAAE,GAEH,WADdgP,EAAOD,EAAO/O,EAAE4O,IAEVnC,EAAI,EACRA,EAAI,EACOA,GAAKyC,IAChBzC,EAAIyC,EAAI,QAEH,GAAc,SAATF,EACNvC,EAAI,GACRA,GAAKyC,GACI,GAEG,KADXzC,GAAKyC,KAEJzC,GAAKyC,GAGIzC,GAAKyC,IAChBzC,GAAKyC,IACKA,IACTzC,GAAKyC,QAGD,GAAKzC,EAAI,GAAKA,GAAKyC,EACzB,MAAM,IAAIC,WAAYC,GAAQ,+FAAgGpP,EAAGyM,KAElI1M,EAAI2O,EAAS1O,IAGJ,GAAgB,IAAX2O,EACbM,GAAOxC,EAAI1M,EAEXkP,GAAOxC,EAAI1M,EAGb,OAAOkP"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 76dcdc8..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index acb12f3..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 702ad26d4948e64b1a617ce249de83e1b57ca601 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:45:08 +0000 Subject: [PATCH 010/140] 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 | 62 +- benchmark/benchmark.js | 403 --- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 573 ----- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 -- manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 2689 +++++++++++++++++++++ stats_node.html | 2689 +++++++++++++++++++++ test/test.js | 403 --- 47 files changed, 5427 insertions(+), 5488 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..dc6e4f3 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..396090c --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 25f81ac..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d56caa2 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2f2ec07 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index be5ab40..58b52be 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..cef82fc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..3c5a977 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From cad31693955aa1e67a0eccf8df62c680ec9bc439 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:50:47 +0000 Subject: [PATCH 011/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index bc49a2b..be5ab40 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From ee2342f3d98f26448c9d760f2bab7e199d40ad42 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:13:23 +0000 Subject: [PATCH 012/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index dc6e4f3..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 396090c..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d56caa2..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2f2ec07..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index cef82fc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 3c5a977..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From e20716061e45b8323de8cef7dc4d762e5f43f1d0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:14:12 +0000 Subject: [PATCH 013/140] 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 | 62 +- benchmark/benchmark.js | 403 --- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 573 ----- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 -- manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 2689 +++++++++++++++++++++ stats_node.html | 2689 +++++++++++++++++++++ test/test.js | 403 --- 48 files changed, 5427 insertions(+), 5562 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index d036bd1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T00:49:54.282Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..dc6e4f3 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..396090c --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 25f81ac..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d56caa2 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2f2ec07 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index be5ab40..58b52be 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..61a6593 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..a176e78 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From d009f22b6496481c8d2566bf88f1d4811a265d7e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:20:33 +0000 Subject: [PATCH 014/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index bc49a2b..be5ab40 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From 69f684502bd5aa90ddfda022729ab26e256d2bea Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:12:41 +0000 Subject: [PATCH 015/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index dc6e4f3..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 396090c..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d56caa2..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2f2ec07..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 61a6593..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index a176e78..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2f47e3c6a4873026477309581d93a5e06e3dc9f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 13:13:32 +0000 Subject: [PATCH 016/140] 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 | 62 +- benchmark/benchmark.js | 403 --- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 573 ----- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 -- manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 2689 +++++++++++++++++++++ stats_node.html | 2689 +++++++++++++++++++++ test/test.js | 403 --- 48 files changed, 5427 insertions(+), 5578 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0c598a2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T00:45:44.201Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..dc6e4f3 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..396090c --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 25f81ac..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The function does not compile if provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The function does not compile if provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The function does not compile if provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d56caa2 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2f2ec07 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index be5ab40..58b52be 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..2502dff --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..4fb049a --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From d85b56f827214d7b5dd9aa751f8eb66848af4727 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 01:12:36 +0000 Subject: [PATCH 017/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index bc49a2b..be5ab40 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From f7167eb9253a5108ce08eedfc68acbe694419faf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 13:11:53 +0000 Subject: [PATCH 018/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index dc6e4f3..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 396090c..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d56caa2..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2f2ec07..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 2502dff..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 4fb049a..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 36024b4c32c727f247e9dd0bd93d66a6735c6877 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 13:12:43 +0000 Subject: [PATCH 019/140] 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 | 62 +- benchmark/benchmark.js | 403 --- benchmark/c/Makefile | 146 -- benchmark/c/benchmark.c | 573 ----- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 -- benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 -- manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 2689 +++++++++++++++++++++ stats_node.html | 2689 +++++++++++++++++++++ test/test.js | 403 --- 48 files changed, 5427 insertions(+), 5578 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ef3eaa5..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T01:10:10.653Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..dc6e4f3 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..396090c --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d56caa2 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2f2ec07 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index be5ab40..58b52be 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..66f5b98 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..cc5686c --- /dev/null +++ b/stats_node.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 0bf7b7ae5927d675ec31872bd001ffba2fe8b8a5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 03:24:10 +0000 Subject: [PATCH 020/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index bc49a2b..be5ab40 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From 4ce38707f788fb37eb6466f6628134d106967827 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 17:00:06 +0000 Subject: [PATCH 021/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 2689 -------------------------------------------- stats_node.html | 2689 -------------------------------------------- 6 files changed, 5386 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index dc6e4f3..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 396090c..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d56caa2..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2f2ec07..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,SCsFR,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,EAGb,OAAOF"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 66f5b98..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index cc5686c..0000000 --- a/stats_node.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 80f01dc027ebd91a77431b1da69f110bc645129c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 17:00:56 +0000 Subject: [PATCH 022/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 4044 +++++++++++++++++++++ stats_node.html | 4044 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 8137 insertions(+), 5578 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5c9cdd3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T00:56:38.137Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..dc6e4f3 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..f5ee664 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d56caa2 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0726bf9 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index be5ab40..58b52be 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..eddb5e2 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..65af04a --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From d86080b365100781f6564b28221d179852386022 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 3 Nov 2022 23:38:00 +0000 Subject: [PATCH 023/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index bc49a2b..be5ab40 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From 97c48da28b4a2f205f289e9d97d36cbfe72989d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 09:40:33 +0000 Subject: [PATCH 024/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4044 -------------------------------------------- stats_node.html | 4044 -------------------------------------------- 6 files changed, 8096 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index dc6e4f3..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index f5ee664..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d56caa2..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0726bf9..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index eddb5e2..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 65af04a..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From c4836136a9d011f2eb3cbe5091578f4370ede508 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 09:41:25 +0000 Subject: [PATCH 025/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 4044 +++++++++++++++++++++ stats_node.html | 4044 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 8137 insertions(+), 5599 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f1699b9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T21:08:08.336Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..dc6e4f3 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..f5ee664 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d56caa2 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..0726bf9 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index be5ab40..58b52be 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..50be281 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..7378aea --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 7ae65c0167ada8033a1fed020ae7ca478dd3520c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 03:22:47 +0000 Subject: [PATCH 026/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index a3b4ad5..980af6b 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From b04bf02e98cfe107b212dbee5683f5a78faae1b9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 10:30:09 +0000 Subject: [PATCH 027/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4044 -------------------------------------------- stats_node.html | 4044 -------------------------------------------- 6 files changed, 8096 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index dc6e4f3..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index f5ee664..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d56caa2..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 0726bf9..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg' ;\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 50be281..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 7378aea..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From c61980204914136356b921ff987f81fc7924e8f7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 10:31:12 +0000 Subject: [PATCH 028/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 4044 +++++++++++++++++++++ stats_node.html | 4044 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 8137 insertions(+), 5604 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 50cdd82..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T00:58:30.929Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..dc6e4f3 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..58ddd9f --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..d56caa2 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..7532e62 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 980af6b..58b52be 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..34a1cc6 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..9e16661 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 6fc973a5497908856f5475d9dcbdab7f0118b571 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 02:38:00 +0000 Subject: [PATCH 029/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 2cee0e3..8f29359 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From 1f8825d24dffad76764c292ba41aaba090f18226 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 09:17:49 +0000 Subject: [PATCH 030/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4044 -------------------------------------------- stats_node.html | 4044 -------------------------------------------- 6 files changed, 8096 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index dc6e4f3..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 58ddd9f..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index d56caa2..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 7532e62..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 34a1cc6..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 9e16661..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 3e17e5dfcfde9bfdbbc34c20ac72a0beac9479f1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 09:18:41 +0000 Subject: [PATCH 031/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 4044 +++++++++++++++++++++ stats_node.html | 4044 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 8137 insertions(+), 5615 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 2fab7ed..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T00:45:51.151Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..5bf0716 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..58ddd9f --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..e878a45 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..7532e62 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 8f29359..58b52be 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..b5e0d91 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..b421ecd --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 9d7ed9b073d3184f4a18678338c76a5bfaf2fbd8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 03:28:42 +0000 Subject: [PATCH 032/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 2cee0e3..8f29359 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-library-manifest": "^0.0.x" }, From b4290b17a2edb3f36342b555a494cb9de7aa7134 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 11:23:55 +0000 Subject: [PATCH 033/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4044 -------------------------------------------- stats_node.html | 4044 -------------------------------------------- 6 files changed, 8096 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 5bf0716..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 58ddd9f..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index e878a45..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 7532e62..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index b5e0d91..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index b421ecd..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4ee15986560f44f70ded8a71b6d243fe6fb3ce6a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 11:24:56 +0000 Subject: [PATCH 034/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 12403 insertions(+), 5615 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index be0953c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T00:55:07.284Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 08ba1ca..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..5bf0716 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..58ddd9f --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..e878a45 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..7532e62 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 8f29359..58b52be 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-library-manifest": "^0.0.x" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-special-floor": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..39b5a76 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..3c31b7c --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 54f733d3a9027c7988d1aab0cf72750fb47a2ffc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 02:20:36 +0000 Subject: [PATCH 035/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 15aec8b..cd0fb1f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-library-manifest": "^0.0.8" }, From a208ad37951c3cb330a460a85abf2005f33d779b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 05:39:33 +0000 Subject: [PATCH 036/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 5bf0716..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 58ddd9f..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index e878a45..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 7532e62..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 39b5a76..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 3c31b7c..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 799c684ee3b35b6c573f84365ab5db860a6008f2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Mar 2023 05:40:34 +0000 Subject: [PATCH 037/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 12403 insertions(+), 5750 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5808b18..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-03-01T01:33:19.627Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..5bf0716 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..58ddd9f --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..e878a45 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..7532e62 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index cd0fb1f..4d35a67 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..bf5ca03 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..0785e3d --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From bb89a481be04555bb206963b49819b42788ece7b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 02:22:22 +0000 Subject: [PATCH 038/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 15aec8b..cd0fb1f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-library-manifest": "^0.0.8" }, From 905b191503143463d36d0c52c4b0c67a6ecc481d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 05:27:05 +0000 Subject: [PATCH 039/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 5bf0716..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 58ddd9f..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index e878a45..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 7532e62..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index bf5ca03..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 0785e3d..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7a65f65d1dce27d10c7fe20de285f735a5922882 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Apr 2023 05:27:48 +0000 Subject: [PATCH 040/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 12403 insertions(+), 5756 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 9d22d93..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-04-01T01:39:16.929Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..5bf0716 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..58ddd9f --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..e878a45 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..7532e62 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index cd0fb1f..4d35a67 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..5069438 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..f7c5525 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 74332c56a455ede0ff6f40a2fa4ec03e62aeb36e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 02:17:58 +0000 Subject: [PATCH 041/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 15aec8b..cd0fb1f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-library-manifest": "^0.0.8" }, From c13b3a43907be266fab3247c80934e4bb0d64548 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 05:16:31 +0000 Subject: [PATCH 042/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 5bf0716..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 58ddd9f..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index e878a45..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 7532e62..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 5069438..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index f7c5525..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From da85793345dea6244a1fbb7356efb7367d526661 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 May 2023 05:17:28 +0000 Subject: [PATCH 043/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 12403 insertions(+), 5756 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 32e2ca8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-05-01T01:36:06.343Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..5bf0716 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..58ddd9f --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..e878a45 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..7532e62 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index cd0fb1f..4d35a67 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..6ba1bfa --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..8459525 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From b5c9c5b47714285845d50be8745883d085438a45 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 02:19:15 +0000 Subject: [PATCH 044/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 15aec8b..cd0fb1f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-library-manifest": "^0.0.8" }, From 08977af5ed776f23ca425aca850cf86679d39ae4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 05:28:32 +0000 Subject: [PATCH 045/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 5bf0716..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 58ddd9f..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index e878a45..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 7532e62..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 6ba1bfa..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 8459525..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7150b6311b940cd145f010a621e22f53cbe7fb7f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 05:29:26 +0000 Subject: [PATCH 046/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 12403 insertions(+), 5756 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index db39944..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T01:36:21.996Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..5bf0716 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..58ddd9f --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..e878a45 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..7532e62 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index cd0fb1f..4d35a67 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..799b9b6 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c2d2a93 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From d4aaf5da298e9360fffed900fa518e9bf2dae330 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 02:19:13 +0000 Subject: [PATCH 047/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 15aec8b..cd0fb1f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-library-manifest": "^0.0.8" }, From 3f4274069a9e50269b7b61f8e34d5ece57ab09d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 05:24:03 +0000 Subject: [PATCH 048/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 5bf0716..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 58ddd9f..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index e878a45..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 7532e62..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 799b9b6..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c2d2a93..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1c480b500c3c6b225e745e966df9e5d534b3058b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 05:24:59 +0000 Subject: [PATCH 049/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 12403 insertions(+), 5756 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3eb1cc0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T01:36:36.899Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..5bf0716 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..58ddd9f --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..e878a45 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..7532e62 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index cd0fb1f..4d35a67 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..7a2c016 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..6c3bce6 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From cb58910ae1ec46548dfe43ff6791b8aed69a7fb8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 02:27:28 +0000 Subject: [PATCH 050/140] Transform error messages --- lib/main.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..7ca4c34 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // diff --git a/package.json b/package.json index 15aec8b..cd0fb1f 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-library-manifest": "^0.0.8" }, From ca43572fa2a30046b92f4a493b5dd77dbfcb4455 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 05:45:46 +0000 Subject: [PATCH 051/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 5bf0716..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 58ddd9f..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index e878a45..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 7532e62..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 7a2c016..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 6c3bce6..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 0aedf07f75b1407d1a64a89787c426800aa2d2ec Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Aug 2023 05:46:38 +0000 Subject: [PATCH 052/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/test.js | 403 -- 48 files changed, 12403 insertions(+), 5756 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 11ad8f3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-08-01T01:39:23.712Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 334eb59..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -197,13 +205,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..5bf0716 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..58ddd9f --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 44f45cc..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..e878a45 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..7532e62 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 7ca4c34..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index cd0fb1f..4d35a67 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.0.8", "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-library-manifest": "^0.0.8" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..7a6eefb --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..85c356c --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 7cebf524cd4d84c50e339218eb432dfe0214671f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 23:11:16 +0000 Subject: [PATCH 053/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..ff24671 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -172,7 +172,7 @@ function sub2ind() { } } } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J,L4', i, j ) ); } s = strides[ i ]; diff --git a/package.json b/package.json index 2841000..1bc8721 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0", "@stdlib/utils-library-manifest": "^0.1.0" }, From 9198d376375aa50d1b5669a162607cf89f5d2525 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 23:47:05 +0000 Subject: [PATCH 054/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 5bf0716..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 58ddd9f..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index e878a45..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],i="https://stdlib.io/e/"+t+"?";for(e=1;e=d&&(a=d-1);else if("wrap"===s)a<0?(a+=d)<0&&0!=(a%=d)&&(a+=d):a>=d&&(a-=d)>=d&&(a%=d);else if(a<0||a>=d)throw new RangeError(e("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",p,a));(l=n[p])<0&&0===t?u-=a*l:u+=a*l}return u}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 7532e62..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,+FAAgGnB,EAAGiB,KAElID,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 7a6eefb..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 85c356c..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9e7f54c42eea7f3cd063d5f581cd3b7586f9c41a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 22 Sep 2023 23:48:04 +0000 Subject: [PATCH 055/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/test.js | 403 -- 51 files changed, 12403 insertions(+), 5790 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 3131977..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 857de24..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -208,13 +216,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..eb16f28 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..074a754 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ 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 1c8dd10..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,u,f,m,v,t,e,n,r,a;for(u=arguments[0],i=arguments[1],s=arguments[2],f=u.length,m=arguments[3+f],o=m.length,t=s,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(r<0||r>=e)throw new RangeError(c('0jX5J',a,r));n=i[a],n<0&&s===0?t-=r*n:t+=r*n}return t}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 6114f4c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAGIE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAEtID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,ICxJjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 78d344c..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..5f602ef --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..689553b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 ff24671..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( '0jX5J,L4', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 1bc8721..2d7f280 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.0" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.0.8", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..d69f8ae --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..333a4cc --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 8409e733897f1352be2d1802ffbb1cf814cff451 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 23 Sep 2023 00:09:05 +0000 Subject: [PATCH 056/140] Update README.md for UMD bundle v0.1.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4b0494a..9b96137 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ limitations under the License. To use in Observable, ```javascript -sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@umd/browser.js' ) +sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.0-umd/browser.js' ) ``` To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build: @@ -66,7 +66,7 @@ var sub2ind = require( 'path/to/vendor/umd/ndarray-base-sub2ind/index.js' ) To include the bundle in a webpage, ```html - + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -225,7 +225,7 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); - + + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -225,7 +230,7 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); - + - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 333a4cc..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7c60e936456b24f3bdcf1c6c0a24cff206ac8bef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 21:15:41 +0000 Subject: [PATCH 060/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/dist/test.js | 403 -- test/test.js | 403 -- 53 files changed, 12403 insertions(+), 6252 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index fca0638..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T01:21:11.383Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b6257c1..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -208,13 +216,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..eb16f28 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..074a754 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ 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 1c8dd10..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,u,f,m,v,t,e,n,r,a;for(u=arguments[0],i=arguments[1],s=arguments[2],f=u.length,m=arguments[3+f],o=m.length,t=s,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(r<0||r>=e)throw new RangeError(c('0jX5J',a,r));n=i[a],n<0&&s===0?t-=r*n:t+=r*n}return t}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 6114f4c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAGIE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAEtID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,ICxJjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 78d344c..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..5f602ef --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..689553b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 ff24671..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( '0jX5J,L4', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 95ae8ba..2d7f280 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.0" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-base-shape2strides": "^0.1.0", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..45d6d55 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..9d6db78 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 9c806b0..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 422ee50d68701d87b2ad7a4ccafcacc9930dbcdf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 02:27:03 +0000 Subject: [PATCH 061/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..ff24671 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -172,7 +172,7 @@ function sub2ind() { } } } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J,L4', i, j ) ); } s = strides[ i ]; diff --git a/package.json b/package.json index 1d9c88e..6aad049 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-library-manifest": "^0.1.1" }, From 0834157aaa6857917e32d801d7e6549d2a29aa67 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 11:22:20 +0000 Subject: [PATCH 062/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index eb16f28..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 074a754..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 5f602ef..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 689553b..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 45d6d55..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 9d6db78..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 13790cff4834dea50592f52e2f95c03f24b70153 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 11:26:37 +0000 Subject: [PATCH 063/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/dist/test.js | 403 -- test/test.js | 403 -- 52 files changed, 12403 insertions(+), 6251 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b6257c1..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -208,13 +216,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..eb16f28 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..074a754 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ 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 1c8dd10..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,u,f,m,v,t,e,n,r,a;for(u=arguments[0],i=arguments[1],s=arguments[2],f=u.length,m=arguments[3+f],o=m.length,t=s,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(r<0||r>=e)throw new RangeError(c('0jX5J',a,r));n=i[a],n<0&&s===0?t-=r*n:t+=r*n}return t}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 6114f4c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAGIE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAEtID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,ICxJjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 78d344c..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..5f602ef --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..689553b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 ff24671..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( '0jX5J,L4', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 6aad049..b6a9bb6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.0", - "@stdlib/ndarray-base-shape2strides": "^0.1.0", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..59816be --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..f3ca996 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 9c806b0..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 21a6311de896b19049ce72f83f069a396957264b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 4 Oct 2023 15:44:04 +0000 Subject: [PATCH 064/140] Update README.md for UMD bundle v0.1.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f1c7338..19b25ec 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ limitations under the License. To use in Observable, ```javascript -sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@umd/browser.js' ) +sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.1.1-umd/browser.js' ) ``` To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build: @@ -66,7 +66,7 @@ var sub2ind = require( 'path/to/vendor/umd/ndarray-base-sub2ind/index.js' ) To include the bundle in a webpage, ```html - + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -225,7 +225,7 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); - + + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -225,7 +230,7 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); - + - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index f3ca996..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 8cdd2e32084b4b0f0b014d54dc326c468a411dbf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 22:21:03 +0000 Subject: [PATCH 068/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/dist/test.js | 403 -- test/test.js | 403 -- 52 files changed, 12403 insertions(+), 6251 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b6257c1..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -208,13 +216,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..eb16f28 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..074a754 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ 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 1c8dd10..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,u,f,m,v,t,e,n,r,a;for(u=arguments[0],i=arguments[1],s=arguments[2],f=u.length,m=arguments[3+f],o=m.length,t=s,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(r<0||r>=e)throw new RangeError(c('0jX5J',a,r));n=i[a],n<0&&s===0?t-=r*n:t+=r*n}return t}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 6114f4c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAGIE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAEtID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,ICxJjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 78d344c..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..5f602ef --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..689553b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 ff24671..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( '0jX5J,L4', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 837c74f..b6a9bb6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..38840ec --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..34f4f2b --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 9c806b0..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From e467b35bab28ff899af01a7cfc60c76f101fc232 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 02:49:59 +0000 Subject: [PATCH 069/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 87a0d37..ff24671 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -172,7 +172,7 @@ function sub2ind() { } } } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J,L4', i, j ) ); } s = strides[ i ]; diff --git a/package.json b/package.json index 209689c..75a7a08 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0", "@stdlib/utils-library-manifest": "^0.1.1" }, From 0d78d71e66c16ad7bb0966d8cce2c31be61c771b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 21:25:25 +0000 Subject: [PATCH 070/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index eb16f28..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 074a754..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 5f602ef..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 689553b..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 38840ec..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 34f4f2b..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3173f393c18328665d6b7bfeb3b2032451e865c8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 21:28:18 +0000 Subject: [PATCH 071/140] 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 | 62 +- benchmark/benchmark.js | 403 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 573 -- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 54 - docs/types/index.d.ts | 130 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 192 - manifest.json | 40 - package.json | 63 +- src/main.c | 105 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 403 -- 53 files changed, 12403 insertions(+), 5890 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a1454c7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T01:22:03.214Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b6257c1..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -208,13 +216,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index d8a4510..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,403 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 5e2e5de..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,573 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version() { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic() { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double() { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10() { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..eb16f28 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..074a754 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ 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 1c8dd10..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,u,f,m,v,t,e,n,r,a;for(u=arguments[0],i=arguments[1],s=arguments[2],f=u.length,m=arguments[3+f],o=m.length,t=s,a=0;a=e&&(r=e-1);else if(v==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(r<0||r>=e)throw new RangeError(c('0jX5J',a,r));n=i[a],n<0&&s===0?t-=r*n:t+=r*n}return t}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 6114f4c..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAGIE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAEtID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,ICxJjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index dbf6671..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,54 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 78d344c..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; // tslint-disable-line max-line-length - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index 23724dd..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..5f602ef --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..689553b --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 ff24671..0000000 --- a/lib/main.js +++ /dev/null @@ -1,192 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode === 'throw' - throw new RangeError( format( '0jX5J,L4', i, j ) ); - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 75a7a08..b6a9bb6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0", - "@stdlib/utils-library-manifest": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 55d3a67..0000000 --- a/src/main.c +++ /dev/null @@ -1,105 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( int64_t ndims, int64_t *shape, int64_t *strides, int64_t offset, int64_t *sub, int64_t nmodes, int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else if ( j < 0 || j >= m ) { // mode == 'error' - return -1; - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..1cba4a8 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..a7efcbd --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 8ed71e8..0000000 --- a/test/test.js +++ /dev/null @@ -1,403 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 6c41b534290bd229881f75194248d1aae7cece8e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:28:29 +0000 Subject: [PATCH 072/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..fe0bf59 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J,L4', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index f548428..4508e05 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-library-manifest": "^0.1.1" }, From a1118638fb63fdcf8dae61dae38f5703ef52e4dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:37:54 +0000 Subject: [PATCH 073/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index eb16f28..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 074a754..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 5f602ef..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if(a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 689553b..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - `throw`: throws an error when a subscript exceeds array dimensions.\n* - `wrap`: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - `clamp`: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns 17\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if ( j < 0 || j >= m ) { // mode === 'throw'\n\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAGD,GAAKE,EAAI,GAAKA,GAAKF,EACzB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAE9CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 1cba4a8..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index a7efcbd..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a4219426d354ee48e7bb816a1e89861aeb1ee77f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 25 Nov 2023 07:40:28 +0000 Subject: [PATCH 074/140] 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 | 62 +- benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 63 +- src/main.c | 110 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 52 files changed, 12403 insertions(+), 6124 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b6257c1..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -209,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9affeac..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..9ec3730 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..766b0b3 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAG/CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..8eb792b --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..eb4c0a5 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAG/CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 fe0bf59..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J,L4', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 4508e05..b6a9bb6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-library-manifest": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/bench": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..9ec390c --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..2a74696 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 698c7e5555017c6a0e6cd19a4e34edbd0a88649d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 02:43:40 +0000 Subject: [PATCH 075/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..fe0bf59 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J,L4', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index f548428..4508e05 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-library-manifest": "^0.1.1" }, From bbd519974b727eaf5a004aa6b1c0d2b1fbfcadeb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:24:34 +0000 Subject: [PATCH 076/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 9ec3730..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 766b0b3..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAG/CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 8eb792b..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index eb4c0a5..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAG/CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 9ec390c..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 2a74696..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 282f5eeb8987cb72b20b881aa49d22dbbd063801 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:27:22 +0000 Subject: [PATCH 077/140] 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 | 62 +- benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 63 +- src/main.c | 110 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 53 files changed, 12403 insertions(+), 6125 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4e32f0f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T01:26:31.295Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b6257c1..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -209,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 9affeac..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..9ec3730 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..766b0b3 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAG/CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..8eb792b --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..eb4c0a5 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAG/CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 fe0bf59..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J,L4', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 4508e05..b6a9bb6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-library-manifest": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/bench": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..c5025e2 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..7814c7e --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 3e695d32ed9ebb8b3df41131b651fe9b632dc373 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 02:04:19 +0000 Subject: [PATCH 078/140] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2c0c8c5..e84a375 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-library-manifest": "^0.1.1" }, From 654f61c2e25bd185da5dc8b7a9e8fbfc65dbe96f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 05:41:31 +0000 Subject: [PATCH 079/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index 9ec3730..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 766b0b3..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAG/CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 8eb792b..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t=n[0],o="https://stdlib.io/e/"+t+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J,L4",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index eb4c0a5..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J,L4', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","c","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UACJC,EAAIF,EAAG,GACPG,EAAI,uBAAuBD,EAAE,IAEjC,IAAMH,EAAI,EAAGA,EAAIC,EAAEI,OAAQL,IAC1BI,GAAK,UAAYE,mBAAoBL,EAAGD,IAEzC,OAAOI,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAjB,EASJ,IANAO,EAAUL,UAAW,GACrBM,EAASN,UAAW,GAGpBO,GADAG,EAAQV,UAAW,GADnBS,GAHAD,EAAQR,UAAW,IAGLG,UAECA,OACfS,EAAMN,EACAR,EAAI,EAAGA,EAAIW,EAAOX,IAAM,CAI7B,GAHAe,EAAIL,EAAOV,GACXiB,EAAIf,UAAWF,EAAE,GAEH,WADda,EAAOD,EAAOZ,EAAES,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,WAAYnB,EAAGiB,KAG/CD,EAAIT,EAASP,IAGJ,GAAgB,IAAXQ,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index c5025e2..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 7814c7e..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7c9f2ffec10fb0b66be3dac7d5b4cfaa0b2f2960 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 05:41:50 +0000 Subject: [PATCH 080/140] 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 | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 53 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 63 +- src/main.c | 110 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 12403 insertions(+), 6131 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 9ae3955..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T01:19:27.699Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 f0db682..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` + +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -209,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 61522e2..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ade6523 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,r;e=this,r=function(){"use strict";function e(e){return"number"==typeof e}function r(e){var r,i="";for(r=0;r0&&(i-=1),a=n.toExponential(i)):a=n.toPrecision(r.precision),r.alternate||(a=l.call(a,b,"$1e"),a=l.call(a,w,"e"),a=l.call(a,h,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return a=l.call(a,f,"e+0$1"),a=l.call(a,g,"e-0$1"),r.alternate&&(a=l.call(a,u,"$1."),a=l.call(a,d,"$1.e")),n>=0&&r.sign&&(a=r.sign+a),a=r.specifier===p.call(r.specifier)?p.call(a):c.call(a)}function v(e){var r,i="";for(r=0;r127)throw new Error("invalid character code. Value: "+n.arg);n.arg=k(c)?String(n.arg):x(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":r||(n.precision=6),n.arg=m(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=y(n.arg,n.width,n.padRight)),p+=n.arg||"",l+=1}return p}var $=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function F(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function I(e){var r,i,a,n;for(i=[],n=0,a=$.exec(e);a;)(r=e.slice(n,$.lastIndex-a[0].length)).length&&i.push(r),i.push(F(a)),n=$.lastIndex,a=$.exec(e);return(r=e.slice(n)).length&&i.push(r),i}function T(e){return"string"==typeof e}function R(e){var r,i,a;if(!T(e))throw new TypeError(R("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=I(e),(i=new Array(arguments.length))[0]=r,a=1;a=c&&(l=c-1);else if("wrap"===s)l<0?(l+=c)<0&&0!=(l%=c)&&(l+=c):l>=c&&(l-=c)>=c&&(l%=c);else if("normalize"===s&&l<0&&(l+=c),l<0||l>=c)throw new RangeError(R("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",f,l));(p=e[f])<0&&0===r?o-=l*p:o+=l*p}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=r(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..241296b --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js","../node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js","../node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js","../node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/main.js","../node_modules/@stdlib/string-base-format-tokenize/lib/main.js","../node_modules/@stdlib/string-format/lib/is_string.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\nimport zeroPad from './zero_pad.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport formatInteger from './format_integer.js';\nimport isString from './is_string.js';\nimport formatDouble from './format_double.js';\nimport spacePad from './space_pad.js';\nimport zeroPad from './zero_pad.js';\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\nvar isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.\n\n\n// FUNCTIONS //\n\n/**\n* Initializes token object with properties of supplied format identifier object or default values if not present.\n*\n* @private\n* @param {Object} token - format identifier object\n* @returns {Object} token object\n*/\nfunction initialize( token ) {\n\tvar out = {};\n\tout.specifier = token.specifier;\n\tout.precision = ( token.precision === void 0 ) ? 1 : token.precision;\n\tout.width = token.width;\n\tout.flags = token.flags || '';\n\tout.mapping = token.mapping;\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Generates string from a token array by interpolating values.\n*\n* @param {Array} tokens - string parts and format identifier objects\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be an array\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var tokens = [ 'beep ', { 'specifier': 's' } ];\n* var out = formatInterpolate( tokens, 'boop' );\n* // returns 'beep boop'\n*/\nfunction formatInterpolate( tokens ) {\n\tvar hasPeriod;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isArray( tokens ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );\n\t}\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\thasPeriod = token.precision !== void 0;\n\t\t\ttoken = initialize( token );\n\t\t\tif ( !token.specifier ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );\n\t\t\t}\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasPeriod ) {\n\t\t\t\tif ( token.precision === '*' ) {\n\t\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t\t}\n\t\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\t\thasPeriod = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInterpolate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\tvar token = {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n\tif ( match[ 4 ] === '.' && match[ 5 ] === void 0 ) {\n\t\ttoken.precision = '1';\n\t}\n\treturn token;\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string into an array of string parts and format identifier objects.\n*\n* @param {string} str - input string\n* @returns {Array} tokens\n*\n* @example\n* var tokens = formatTokenize( 'Hello %s!' );\n* // returns [ 'Hello ', {...}, '!' ]\n*/\nfunction formatTokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nexport default formatTokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport interpolate from '@stdlib/string-base-format-interpolate';\nimport tokenize from '@stdlib/string-base-format-tokenize';\nimport isString from './is_string.js';\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default format;\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 format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["isNumber","value","zeros","n","i","out","zeroPad","str","width","right","negative","pad","length","startsWithMinus","substr","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","formatInteger","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","isString","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","spaces","spacePad","fromCharCode","isnan","isNaN","isArray","Array","initialize","flags","mapping","formatInterpolate","tokens","hasPeriod","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","RE","parse","match","formatTokenize","content","prev","exec","slice","lastIndex","push","format","args","tokenize","interpolate","apply","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","RangeError"],"mappings":";yCAsCA,SAASA,EAAUC,GAClB,MAA0B,iBAAVA,CACjB,CCAA,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASC,EAASC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,EACb,CAoCMM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,CAaT,CCpDA,IAAIQ,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAajC,SAASC,EAAeC,GACvB,IAAIC,EACAlB,EACAD,EAEJ,OAASkB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAlB,EAAMiB,EAAMG,IACZrB,EAAIsB,SAAUrB,EAAK,KACbsB,SAAUvB,GAAM,CACrB,IAAMJ,EAAUK,GACf,MAAM,IAAIuB,MAAO,2BAA6BvB,GAE/CD,EAAI,CACJ,CAkCD,OAjCKA,EAAI,IAA2B,MAApBkB,EAAME,WAA8B,KAATD,KAC1CnB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAIyB,SAAUN,GAClBD,EAAMQ,YACVzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAE5C1B,EAAM,IAAMA,IAEZA,EAAMD,EAAEyB,SAAUN,GACZnB,GAAMkB,EAAMQ,UAENR,EAAMQ,YACjBzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAF3C1B,EAAM,GAIFiB,EAAMU,OACV3B,EAAMiB,EAAMU,KAAO3B,IAGP,KAATkB,IACCD,EAAMW,YACV5B,EAAM,KAAOA,GAEdA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,IAEJ,IAATkB,GACCD,EAAMW,WAAiC,MAApB5B,EAAI8B,OAAQ,KACnC9B,EAAM,IAAMA,GAGPA,CACR,CC3EA,SAAS+B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCXA,IAAIoC,EAAMC,KAAKD,IACXtB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BmB,EAAUvB,OAAOC,UAAUsB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAazB,SAASC,EAAczB,GACtB,IAAI0B,EACA3C,EACA4C,EAAIC,WAAY5B,EAAMG,KAC1B,IAAME,SAAUsB,GAAM,CACrB,IAAMjD,EAAUsB,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2CvB,GAG7D4C,EAAI3B,EAAMG,GACV,CACD,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJnB,EAAM4C,EAAEE,cAAe7B,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJzB,EAAM4C,EAAEG,QAAS9B,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCO,EAAKY,GAAM,OACfD,EAAS1B,EAAMQ,WACD,IACbkB,GAAU,GAEX3C,EAAM4C,EAAEE,cAAeH,IAEvB3C,EAAM4C,EAAEI,YAAa/B,EAAMQ,WAEtBR,EAAMW,YACX5B,EAAMkC,EAAQL,KAAM7B,EAAKyC,EAAoB,OAC7CzC,EAAMkC,EAAQL,KAAM7B,EAAKwC,EAAoB,KAC7CxC,EAAMkC,EAAQL,KAAM7B,EAAKuC,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIhB,MAAO,mCAAqCN,EAAME,WAc7D,OAZAnB,EAAMkC,EAAQL,KAAM7B,EAAKmC,EAAmB,SAC5CnC,EAAMkC,EAAQL,KAAM7B,EAAKoC,EAAmB,SACvCnB,EAAMW,YACV5B,EAAMkC,EAAQL,KAAM7B,EAAKqC,EAAgB,OACzCrC,EAAMkC,EAAQL,KAAM7B,EAAKsC,EAAsB,SAE3CM,GAAK,GAAK3B,EAAMU,OACpB3B,EAAMiB,EAAMU,KAAO3B,GAEpBA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,EAElB,CC5EA,SAASiD,EAAQnD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASkD,EAAUhD,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAM+C,EAAQ3C,GACd2C,EAAQ3C,GAAQJ,CAElB,CC5BA,IAAIiD,EAAexC,OAAOwC,aACtBC,EAAQC,MACRC,EAAUC,MAAMD,QAYpB,SAASE,EAAYvC,GACpB,IAAIjB,EAAM,CAAA,EAMV,OALAA,EAAImB,UAAYF,EAAME,UACtBnB,EAAIyB,eAAkC,IAApBR,EAAMQ,UAAyB,EAAIR,EAAMQ,UAC3DzB,EAAIG,MAAQc,EAAMd,MAClBH,EAAIyD,MAAQxC,EAAMwC,OAAS,GAC3BzD,EAAI0D,QAAUzC,EAAMyC,QACb1D,CACR,CAmBA,SAAS2D,EAAmBC,GAC3B,IAAIC,EACAJ,EACAxC,EACA6C,EACAC,EACA/D,EACAgE,EACAjE,EACAkE,EAEJ,IAAMX,EAASM,GACd,MAAM,IAAIM,UAAW,8DAAgEN,EAAS,MAI/F,IAFA5D,EAAM,GACNgE,EAAM,EACAjE,EAAI,EAAGA,EAAI6D,EAAOrD,OAAQR,IAE/B,GAAKgC,EADLd,EAAQ2C,EAAQ7D,IAEfC,GAAOiB,MACD,CAGN,GAFA4C,OAAgC,IAApB5C,EAAMQ,YAClBR,EAAQuC,EAAYvC,IACRE,UACX,MAAM,IAAI+C,UAAW,oEAAqEnE,EAAG,cAAgBkB,EAAQ,MAMtH,IAJKA,EAAMyC,UACVM,EAAM/C,EAAMyC,SAEbD,EAAQxC,EAAMwC,MACRQ,EAAI,EAAGA,EAAIR,EAAMlD,OAAQ0D,IAE9B,OADAH,EAAOL,EAAM3B,OAAQmC,IAErB,IAAK,IACJhD,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAMkD,UAAW,EACjB,MACD,IAAK,IACJlD,EAAMkD,SAAWV,EAAMW,QAAS,KAAQ,EACxC,MACD,IAAK,IACJnD,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBuC,GAGtC,GAAqB,MAAhB7C,EAAMd,MAAgB,CAG1B,GAFAc,EAAMd,MAAQkB,SAAUgD,UAAWL,GAAO,IAC1CA,GAAO,EACFZ,EAAOnC,EAAMd,OACjB,MAAM,IAAI+D,UAAW,wCAA0CF,EAAM,6BAA+B/C,EAAMd,MAAQ,MAE9Gc,EAAMd,MAAQ,IAClBc,EAAMS,UAAW,EACjBT,EAAMd,OAASc,EAAMd,MAEtB,CACD,GAAK0D,GACqB,MAApB5C,EAAMQ,UAAoB,CAG9B,GAFAR,EAAMQ,UAAYJ,SAAUgD,UAAWL,GAAO,IAC9CA,GAAO,EACFZ,EAAOnC,EAAMQ,WACjB,MAAM,IAAIyC,UAAW,4CAA8CF,EAAM,6BAA+B/C,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBoC,GAAY,EAEb,CAGF,OADA5C,EAAMG,IAAMiD,UAAWL,GACd/C,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEC0C,IACJ5C,EAAMkD,UAAW,GAElBlD,EAAMG,IAAMJ,EAAeC,GAC3B,MACD,IAAK,IAEJA,EAAMqD,SAAW,EAAgBrD,EAAMQ,WAAa,EACpD,MACD,IAAK,IAEJ,IAAM2B,EAAOnC,EAAMG,KAAQ,CAE1B,IADA2C,EAAM1C,SAAUJ,EAAMG,IAAK,KAChB,GAAK2C,EAAM,IACrB,MAAM,IAAIxC,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgC,EAAOW,GACpBpD,OAAQM,EAAMG,KACd+B,EAAcY,EACf,CACD,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEEF,IACL5C,EAAMQ,UAAY,GAEnBR,EAAMG,IAAMsB,EAAczB,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAMqD,UAAY,GAAKrD,EAAMG,IAAIb,OAASU,EAAMqD,WACpDrD,EAAMG,IAAMH,EAAMG,IAAImD,UAAW,EAAGtD,EAAMqD,WAEtCrD,EAAMkD,SACVlD,EAAMG,IAAMnB,EAASgB,EAAMG,IAAKH,EAAMd,OAASc,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMd,QACjBc,EAAMG,IAAM8B,EAAUjC,EAAMG,IAAKH,EAAMd,MAAOc,EAAMS,WAErD1B,GAAOiB,EAAMG,KAAO,GACpB4C,GAAO,CACP,CAEF,OAAOhE,CACR,CC3LA,IAAIwE,EAAK,6EAYT,SAASC,EAAOC,GACf,IAAIzD,EAAQ,CACXyC,QAAagB,EAAO,GAAQrD,SAAUqD,EAAO,GAAK,SAAO,EACzDjB,MAASiB,EAAO,GAChBvE,MAASuE,EAAO,GAChBjD,UAAaiD,EAAO,GACpBvD,UAAauD,EAAO,IAKrB,MAHoB,MAAfA,EAAO,SAA8B,IAAfA,EAAO,KACjCzD,EAAMQ,UAAY,KAEZR,CACR,CAeA,SAAS0D,EAAgBzE,GACxB,IAAI0E,EACAhB,EACAc,EACAG,EAKJ,IAHAjB,EAAS,GACTiB,EAAO,EACPH,EAAQF,EAAGM,KAAM5E,GACTwE,IACPE,EAAU1E,EAAI6E,MAAOF,EAAML,EAAGQ,UAAYN,EAAO,GAAInE,SACxCA,QACZqD,EAAOqB,KAAML,GAEdhB,EAAOqB,KAAMR,EAAOC,IACpBG,EAAOL,EAAGQ,UACVN,EAAQF,EAAGM,KAAM5E,GAMlB,OAJA0E,EAAU1E,EAAI6E,MAAOF,IACRtE,QACZqD,EAAOqB,KAAML,GAEPhB,CACR,CClDA,SAAS7B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCUA,SAASsF,EAAQhF,GAChB,IAAI0D,EACAuB,EACApF,EAEJ,IAAMgC,EAAU7B,GACf,MAAM,IAAIgE,UAAWgB,EAAQ,kEAAmEhF,IAKjG,IAHA0D,EAASwB,EAAUlF,IACnBiF,EAAO,IAAI5B,MAAOc,UAAU9D,SACtB,GAAMqD,EACN7D,EAAI,EAAGA,EAAIoF,EAAK5E,OAAQR,IAC7BoF,EAAMpF,GAAMsE,UAAWtE,GAExB,OAAOsF,EAAYC,MAAO,KAAMH,EACjC,QCkEA,WACC,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EACAlE,EASJ,IANAwF,EAAUlB,UAAW,GACrBmB,EAASnB,UAAW,GAGpBoB,GADAG,EAAQvB,UAAW,GADnBsB,GAHAD,EAAQrB,UAAW,IAGL9D,UAECA,OACfuF,EAAMN,EACAzF,EAAI,EAAGA,EAAI4F,EAAO5F,IAAM,CAI7B,GAHAgG,EAAIL,EAAO3F,GACXkE,EAAII,UAAWtE,EAAE,GAEH,WADd8F,EAAOD,EAAO7F,EAAE0F,IAEVxB,EAAI,EACRA,EAAI,EACOA,GAAK8B,IAChB9B,EAAI8B,EAAI,QAEH,GAAc,SAATF,EACN5B,EAAI,GACRA,GAAK8B,GACI,GAEG,IADX9B,GAAK8B,KAEJ9B,GAAK8B,GAGI9B,GAAK8B,IAChB9B,GAAK8B,IACKA,IACT9B,GAAK8B,QAOP,GAHc,cAATF,GAAwB5B,EAAI,IAChCA,GAAK8B,GAED9B,EAAI,GAAKA,GAAK8B,EAClB,MAAM,IAAIE,WAAYf,EAAQ,+FAAgGnF,EAAGkE,KAGnI+B,EAAIT,EAASxF,IAGJ,GAAgB,IAAXyF,EACbM,GAAO7B,EAAI+B,EAEXF,GAAO7B,EAAI+B,CAEZ,CACD,OAAOF,CACR"} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..3188d51 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,r;e=this,r=function(){"use strict";function e(e){return"number"==typeof e}function r(e){var r,i="";for(r=0;r0&&(i-=1),a=n.toExponential(i)):a=n.toPrecision(r.precision),r.alternate||(a=l.call(a,b,"$1e"),a=l.call(a,w,"e"),a=l.call(a,h,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return a=l.call(a,f,"e+0$1"),a=l.call(a,g,"e-0$1"),r.alternate&&(a=l.call(a,u,"$1."),a=l.call(a,d,"$1.e")),n>=0&&r.sign&&(a=r.sign+a),a=r.specifier===p.call(r.specifier)?p.call(a):c.call(a)}function v(e){var r,i="";for(r=0;r127)throw new Error("invalid character code. Value: "+n.arg);n.arg=k(c)?String(n.arg):x(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":r||(n.precision=6),n.arg=m(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=y(n.arg,n.width,n.padRight)),p+=n.arg||"",l+=1}return p}var $=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function F(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function I(e){var r,i,a,n;for(i=[],n=0,a=$.exec(e);a;)(r=e.slice(n,$.lastIndex-a[0].length)).length&&i.push(r),i.push(F(a)),n=$.lastIndex,a=$.exec(e);return(r=e.slice(n)).length&&i.push(r),i}function T(e){return"string"==typeof e}function R(e){var r,i,a;if(!T(e))throw new TypeError(R("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=I(e),(i=new Array(arguments.length))[0]=r,a=1;a=c&&(l=c-1);else if("wrap"===s)l<0?(l+=c)<0&&0!=(l%=c)&&(l+=c):l>=c&&(l-=c)>=c&&(l%=c);else if("normalize"===s&&l<0&&(l+=c),l<0||l>=c)throw new RangeError(R("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",f,l));(p=e[f])<0&&0===r?o-=l*p:o+=l*p}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=r(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..c53e67e --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js","../node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js","../node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js","../node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/main.js","../node_modules/@stdlib/string-base-format-tokenize/lib/main.js","../node_modules/@stdlib/string-format/lib/is_string.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\nimport zeroPad from './zero_pad.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport formatInteger from './format_integer.js';\nimport isString from './is_string.js';\nimport formatDouble from './format_double.js';\nimport spacePad from './space_pad.js';\nimport zeroPad from './zero_pad.js';\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\nvar isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.\n\n\n// FUNCTIONS //\n\n/**\n* Initializes token object with properties of supplied format identifier object or default values if not present.\n*\n* @private\n* @param {Object} token - format identifier object\n* @returns {Object} token object\n*/\nfunction initialize( token ) {\n\tvar out = {};\n\tout.specifier = token.specifier;\n\tout.precision = ( token.precision === void 0 ) ? 1 : token.precision;\n\tout.width = token.width;\n\tout.flags = token.flags || '';\n\tout.mapping = token.mapping;\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Generates string from a token array by interpolating values.\n*\n* @param {Array} tokens - string parts and format identifier objects\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be an array\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var tokens = [ 'beep ', { 'specifier': 's' } ];\n* var out = formatInterpolate( tokens, 'boop' );\n* // returns 'beep boop'\n*/\nfunction formatInterpolate( tokens ) {\n\tvar hasPeriod;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isArray( tokens ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );\n\t}\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\thasPeriod = token.precision !== void 0;\n\t\t\ttoken = initialize( token );\n\t\t\tif ( !token.specifier ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );\n\t\t\t}\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasPeriod ) {\n\t\t\t\tif ( token.precision === '*' ) {\n\t\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t\t}\n\t\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\t\thasPeriod = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInterpolate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\tvar token = {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n\tif ( match[ 4 ] === '.' && match[ 5 ] === void 0 ) {\n\t\ttoken.precision = '1';\n\t}\n\treturn token;\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string into an array of string parts and format identifier objects.\n*\n* @param {string} str - input string\n* @returns {Array} tokens\n*\n* @example\n* var tokens = formatTokenize( 'Hello %s!' );\n* // returns [ 'Hello ', {...}, '!' ]\n*/\nfunction formatTokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nexport default formatTokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport interpolate from '@stdlib/string-base-format-interpolate';\nimport tokenize from '@stdlib/string-base-format-tokenize';\nimport isString from './is_string.js';\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default format;\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 format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["isNumber","value","zeros","n","i","out","zeroPad","str","width","right","negative","pad","length","startsWithMinus","substr","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","formatInteger","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","isString","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","spaces","spacePad","fromCharCode","isnan","isNaN","isArray","Array","initialize","flags","mapping","formatInterpolate","tokens","hasPeriod","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","RE","parse","match","formatTokenize","content","prev","exec","slice","lastIndex","push","format","args","tokenize","interpolate","apply","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","RangeError"],"mappings":";yCAsCA,SAASA,EAAUC,GAClB,MAA0B,iBAAVA,CACjB,CCAA,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASC,EAASC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,EACb,CAoCMM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,CAaT,CCpDA,IAAIQ,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAajC,SAASC,EAAeC,GACvB,IAAIC,EACAlB,EACAD,EAEJ,OAASkB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAlB,EAAMiB,EAAMG,IACZrB,EAAIsB,SAAUrB,EAAK,KACbsB,SAAUvB,GAAM,CACrB,IAAMJ,EAAUK,GACf,MAAM,IAAIuB,MAAO,2BAA6BvB,GAE/CD,EAAI,CACJ,CAkCD,OAjCKA,EAAI,IAA2B,MAApBkB,EAAME,WAA8B,KAATD,KAC1CnB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAIyB,SAAUN,GAClBD,EAAMQ,YACVzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAE5C1B,EAAM,IAAMA,IAEZA,EAAMD,EAAEyB,SAAUN,GACZnB,GAAMkB,EAAMQ,UAENR,EAAMQ,YACjBzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAF3C1B,EAAM,GAIFiB,EAAMU,OACV3B,EAAMiB,EAAMU,KAAO3B,IAGP,KAATkB,IACCD,EAAMW,YACV5B,EAAM,KAAOA,GAEdA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,IAEJ,IAATkB,GACCD,EAAMW,WAAiC,MAApB5B,EAAI8B,OAAQ,KACnC9B,EAAM,IAAMA,GAGPA,CACR,CC3EA,SAAS+B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCXA,IAAIoC,EAAMC,KAAKD,IACXtB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BmB,EAAUvB,OAAOC,UAAUsB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAazB,SAASC,EAAczB,GACtB,IAAI0B,EACA3C,EACA4C,EAAIC,WAAY5B,EAAMG,KAC1B,IAAME,SAAUsB,GAAM,CACrB,IAAMjD,EAAUsB,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2CvB,GAG7D4C,EAAI3B,EAAMG,GACV,CACD,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJnB,EAAM4C,EAAEE,cAAe7B,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJzB,EAAM4C,EAAEG,QAAS9B,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCO,EAAKY,GAAM,OACfD,EAAS1B,EAAMQ,WACD,IACbkB,GAAU,GAEX3C,EAAM4C,EAAEE,cAAeH,IAEvB3C,EAAM4C,EAAEI,YAAa/B,EAAMQ,WAEtBR,EAAMW,YACX5B,EAAMkC,EAAQL,KAAM7B,EAAKyC,EAAoB,OAC7CzC,EAAMkC,EAAQL,KAAM7B,EAAKwC,EAAoB,KAC7CxC,EAAMkC,EAAQL,KAAM7B,EAAKuC,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIhB,MAAO,mCAAqCN,EAAME,WAc7D,OAZAnB,EAAMkC,EAAQL,KAAM7B,EAAKmC,EAAmB,SAC5CnC,EAAMkC,EAAQL,KAAM7B,EAAKoC,EAAmB,SACvCnB,EAAMW,YACV5B,EAAMkC,EAAQL,KAAM7B,EAAKqC,EAAgB,OACzCrC,EAAMkC,EAAQL,KAAM7B,EAAKsC,EAAsB,SAE3CM,GAAK,GAAK3B,EAAMU,OACpB3B,EAAMiB,EAAMU,KAAO3B,GAEpBA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,EAElB,CC5EA,SAASiD,EAAQnD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASkD,EAAUhD,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAM+C,EAAQ3C,GACd2C,EAAQ3C,GAAQJ,CAElB,CC5BA,IAAIiD,EAAexC,OAAOwC,aACtBC,EAAQC,MACRC,EAAUC,MAAMD,QAYpB,SAASE,EAAYvC,GACpB,IAAIjB,EAAM,CAAA,EAMV,OALAA,EAAImB,UAAYF,EAAME,UACtBnB,EAAIyB,eAAkC,IAApBR,EAAMQ,UAAyB,EAAIR,EAAMQ,UAC3DzB,EAAIG,MAAQc,EAAMd,MAClBH,EAAIyD,MAAQxC,EAAMwC,OAAS,GAC3BzD,EAAI0D,QAAUzC,EAAMyC,QACb1D,CACR,CAmBA,SAAS2D,EAAmBC,GAC3B,IAAIC,EACAJ,EACAxC,EACA6C,EACAC,EACA/D,EACAgE,EACAjE,EACAkE,EAEJ,IAAMX,EAASM,GACd,MAAM,IAAIM,UAAW,8DAAgEN,EAAS,MAI/F,IAFA5D,EAAM,GACNgE,EAAM,EACAjE,EAAI,EAAGA,EAAI6D,EAAOrD,OAAQR,IAE/B,GAAKgC,EADLd,EAAQ2C,EAAQ7D,IAEfC,GAAOiB,MACD,CAGN,GAFA4C,OAAgC,IAApB5C,EAAMQ,YAClBR,EAAQuC,EAAYvC,IACRE,UACX,MAAM,IAAI+C,UAAW,oEAAqEnE,EAAG,cAAgBkB,EAAQ,MAMtH,IAJKA,EAAMyC,UACVM,EAAM/C,EAAMyC,SAEbD,EAAQxC,EAAMwC,MACRQ,EAAI,EAAGA,EAAIR,EAAMlD,OAAQ0D,IAE9B,OADAH,EAAOL,EAAM3B,OAAQmC,IAErB,IAAK,IACJhD,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAMkD,UAAW,EACjB,MACD,IAAK,IACJlD,EAAMkD,SAAWV,EAAMW,QAAS,KAAQ,EACxC,MACD,IAAK,IACJnD,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBuC,GAGtC,GAAqB,MAAhB7C,EAAMd,MAAgB,CAG1B,GAFAc,EAAMd,MAAQkB,SAAUgD,UAAWL,GAAO,IAC1CA,GAAO,EACFZ,EAAOnC,EAAMd,OACjB,MAAM,IAAI+D,UAAW,wCAA0CF,EAAM,6BAA+B/C,EAAMd,MAAQ,MAE9Gc,EAAMd,MAAQ,IAClBc,EAAMS,UAAW,EACjBT,EAAMd,OAASc,EAAMd,MAEtB,CACD,GAAK0D,GACqB,MAApB5C,EAAMQ,UAAoB,CAG9B,GAFAR,EAAMQ,UAAYJ,SAAUgD,UAAWL,GAAO,IAC9CA,GAAO,EACFZ,EAAOnC,EAAMQ,WACjB,MAAM,IAAIyC,UAAW,4CAA8CF,EAAM,6BAA+B/C,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBoC,GAAY,EAEb,CAGF,OADA5C,EAAMG,IAAMiD,UAAWL,GACd/C,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEC0C,IACJ5C,EAAMkD,UAAW,GAElBlD,EAAMG,IAAMJ,EAAeC,GAC3B,MACD,IAAK,IAEJA,EAAMqD,SAAW,EAAgBrD,EAAMQ,WAAa,EACpD,MACD,IAAK,IAEJ,IAAM2B,EAAOnC,EAAMG,KAAQ,CAE1B,IADA2C,EAAM1C,SAAUJ,EAAMG,IAAK,KAChB,GAAK2C,EAAM,IACrB,MAAM,IAAIxC,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgC,EAAOW,GACpBpD,OAAQM,EAAMG,KACd+B,EAAcY,EACf,CACD,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEEF,IACL5C,EAAMQ,UAAY,GAEnBR,EAAMG,IAAMsB,EAAczB,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAMqD,UAAY,GAAKrD,EAAMG,IAAIb,OAASU,EAAMqD,WACpDrD,EAAMG,IAAMH,EAAMG,IAAImD,UAAW,EAAGtD,EAAMqD,WAEtCrD,EAAMkD,SACVlD,EAAMG,IAAMnB,EAASgB,EAAMG,IAAKH,EAAMd,OAASc,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMd,QACjBc,EAAMG,IAAM8B,EAAUjC,EAAMG,IAAKH,EAAMd,MAAOc,EAAMS,WAErD1B,GAAOiB,EAAMG,KAAO,GACpB4C,GAAO,CACP,CAEF,OAAOhE,CACR,CC3LA,IAAIwE,EAAK,6EAYT,SAASC,EAAOC,GACf,IAAIzD,EAAQ,CACXyC,QAAagB,EAAO,GAAQrD,SAAUqD,EAAO,GAAK,SAAO,EACzDjB,MAASiB,EAAO,GAChBvE,MAASuE,EAAO,GAChBjD,UAAaiD,EAAO,GACpBvD,UAAauD,EAAO,IAKrB,MAHoB,MAAfA,EAAO,SAA8B,IAAfA,EAAO,KACjCzD,EAAMQ,UAAY,KAEZR,CACR,CAeA,SAAS0D,EAAgBzE,GACxB,IAAI0E,EACAhB,EACAc,EACAG,EAKJ,IAHAjB,EAAS,GACTiB,EAAO,EACPH,EAAQF,EAAGM,KAAM5E,GACTwE,IACPE,EAAU1E,EAAI6E,MAAOF,EAAML,EAAGQ,UAAYN,EAAO,GAAInE,SACxCA,QACZqD,EAAOqB,KAAML,GAEdhB,EAAOqB,KAAMR,EAAOC,IACpBG,EAAOL,EAAGQ,UACVN,EAAQF,EAAGM,KAAM5E,GAMlB,OAJA0E,EAAU1E,EAAI6E,MAAOF,IACRtE,QACZqD,EAAOqB,KAAML,GAEPhB,CACR,CClDA,SAAS7B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCUA,SAASsF,EAAQhF,GAChB,IAAI0D,EACAuB,EACApF,EAEJ,IAAMgC,EAAU7B,GACf,MAAM,IAAIgE,UAAWgB,EAAQ,kEAAmEhF,IAKjG,IAHA0D,EAASwB,EAAUlF,IACnBiF,EAAO,IAAI5B,MAAOc,UAAU9D,SACtB,GAAMqD,EACN7D,EAAI,EAAGA,EAAIoF,EAAK5E,OAAQR,IAC7BoF,EAAMpF,GAAMsE,UAAWtE,GAExB,OAAOsF,EAAYC,MAAO,KAAMH,EACjC,QCkEA,WACC,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EACAlE,EASJ,IANAwF,EAAUlB,UAAW,GACrBmB,EAASnB,UAAW,GAGpBoB,GADAG,EAAQvB,UAAW,GADnBsB,GAHAD,EAAQrB,UAAW,IAGL9D,UAECA,OACfuF,EAAMN,EACAzF,EAAI,EAAGA,EAAI4F,EAAO5F,IAAM,CAI7B,GAHAgG,EAAIL,EAAO3F,GACXkE,EAAII,UAAWtE,EAAE,GAEH,WADd8F,EAAOD,EAAO7F,EAAE0F,IAEVxB,EAAI,EACRA,EAAI,EACOA,GAAK8B,IAChB9B,EAAI8B,EAAI,QAEH,GAAc,SAATF,EACN5B,EAAI,GACRA,GAAK8B,GACI,GAEG,IADX9B,GAAK8B,KAEJ9B,GAAK8B,GAGI9B,GAAK8B,IAChB9B,GAAK8B,IACKA,IACT9B,GAAK8B,QAOP,GAHc,cAATF,GAAwB5B,EAAI,IAChCA,GAAK8B,GAED9B,EAAI,GAAKA,GAAK8B,EAClB,MAAM,IAAIE,WAAYf,EAAQ,+FAAgGnF,EAAGkE,KAGnI+B,EAAIT,EAASxF,IAGJ,GAAgB,IAAXyF,EACbM,GAAO7B,EAAI+B,EAEXF,GAAO7B,EAAI+B,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 2e347d0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/string-format' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index e84a375..b6a9bb6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-library-manifest": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..af41e62 --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..97e9fec --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 2442abb556d9d128e5ae73298d0c41e9033a97d0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 02:06:33 +0000 Subject: [PATCH 081/140] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2c0c8c5..e84a375 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0", "@stdlib/utils-library-manifest": "^0.1.1" }, From 7766c807d72d823dedca2d25ec31d105811fb657 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:41:17 +0000 Subject: [PATCH 082/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ade6523..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,r;e=this,r=function(){"use strict";function e(e){return"number"==typeof e}function r(e){var r,i="";for(r=0;r0&&(i-=1),a=n.toExponential(i)):a=n.toPrecision(r.precision),r.alternate||(a=l.call(a,b,"$1e"),a=l.call(a,w,"e"),a=l.call(a,h,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return a=l.call(a,f,"e+0$1"),a=l.call(a,g,"e-0$1"),r.alternate&&(a=l.call(a,u,"$1."),a=l.call(a,d,"$1.e")),n>=0&&r.sign&&(a=r.sign+a),a=r.specifier===p.call(r.specifier)?p.call(a):c.call(a)}function v(e){var r,i="";for(r=0;r127)throw new Error("invalid character code. Value: "+n.arg);n.arg=k(c)?String(n.arg):x(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":r||(n.precision=6),n.arg=m(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=y(n.arg,n.width,n.padRight)),p+=n.arg||"",l+=1}return p}var $=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function F(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function I(e){var r,i,a,n;for(i=[],n=0,a=$.exec(e);a;)(r=e.slice(n,$.lastIndex-a[0].length)).length&&i.push(r),i.push(F(a)),n=$.lastIndex,a=$.exec(e);return(r=e.slice(n)).length&&i.push(r),i}function T(e){return"string"==typeof e}function R(e){var r,i,a;if(!T(e))throw new TypeError(R("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=I(e),(i=new Array(arguments.length))[0]=r,a=1;a=c&&(l=c-1);else if("wrap"===s)l<0?(l+=c)<0&&0!=(l%=c)&&(l+=c):l>=c&&(l-=c)>=c&&(l%=c);else if("normalize"===s&&l<0&&(l+=c),l<0||l>=c)throw new RangeError(R("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",f,l));(p=e[f])<0&&0===r?o-=l*p:o+=l*p}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=r(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 241296b..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js","../node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js","../node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js","../node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/main.js","../node_modules/@stdlib/string-base-format-tokenize/lib/main.js","../node_modules/@stdlib/string-format/lib/is_string.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\nimport zeroPad from './zero_pad.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport formatInteger from './format_integer.js';\nimport isString from './is_string.js';\nimport formatDouble from './format_double.js';\nimport spacePad from './space_pad.js';\nimport zeroPad from './zero_pad.js';\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\nvar isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.\n\n\n// FUNCTIONS //\n\n/**\n* Initializes token object with properties of supplied format identifier object or default values if not present.\n*\n* @private\n* @param {Object} token - format identifier object\n* @returns {Object} token object\n*/\nfunction initialize( token ) {\n\tvar out = {};\n\tout.specifier = token.specifier;\n\tout.precision = ( token.precision === void 0 ) ? 1 : token.precision;\n\tout.width = token.width;\n\tout.flags = token.flags || '';\n\tout.mapping = token.mapping;\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Generates string from a token array by interpolating values.\n*\n* @param {Array} tokens - string parts and format identifier objects\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be an array\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var tokens = [ 'beep ', { 'specifier': 's' } ];\n* var out = formatInterpolate( tokens, 'boop' );\n* // returns 'beep boop'\n*/\nfunction formatInterpolate( tokens ) {\n\tvar hasPeriod;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isArray( tokens ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );\n\t}\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\thasPeriod = token.precision !== void 0;\n\t\t\ttoken = initialize( token );\n\t\t\tif ( !token.specifier ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );\n\t\t\t}\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasPeriod ) {\n\t\t\t\tif ( token.precision === '*' ) {\n\t\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t\t}\n\t\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\t\thasPeriod = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInterpolate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\tvar token = {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n\tif ( match[ 4 ] === '.' && match[ 5 ] === void 0 ) {\n\t\ttoken.precision = '1';\n\t}\n\treturn token;\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string into an array of string parts and format identifier objects.\n*\n* @param {string} str - input string\n* @returns {Array} tokens\n*\n* @example\n* var tokens = formatTokenize( 'Hello %s!' );\n* // returns [ 'Hello ', {...}, '!' ]\n*/\nfunction formatTokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nexport default formatTokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport interpolate from '@stdlib/string-base-format-interpolate';\nimport tokenize from '@stdlib/string-base-format-tokenize';\nimport isString from './is_string.js';\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default format;\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 format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["isNumber","value","zeros","n","i","out","zeroPad","str","width","right","negative","pad","length","startsWithMinus","substr","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","formatInteger","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","isString","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","spaces","spacePad","fromCharCode","isnan","isNaN","isArray","Array","initialize","flags","mapping","formatInterpolate","tokens","hasPeriod","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","RE","parse","match","formatTokenize","content","prev","exec","slice","lastIndex","push","format","args","tokenize","interpolate","apply","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","RangeError"],"mappings":";yCAsCA,SAASA,EAAUC,GAClB,MAA0B,iBAAVA,CACjB,CCAA,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASC,EAASC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,EACb,CAoCMM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,CAaT,CCpDA,IAAIQ,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAajC,SAASC,EAAeC,GACvB,IAAIC,EACAlB,EACAD,EAEJ,OAASkB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAlB,EAAMiB,EAAMG,IACZrB,EAAIsB,SAAUrB,EAAK,KACbsB,SAAUvB,GAAM,CACrB,IAAMJ,EAAUK,GACf,MAAM,IAAIuB,MAAO,2BAA6BvB,GAE/CD,EAAI,CACJ,CAkCD,OAjCKA,EAAI,IAA2B,MAApBkB,EAAME,WAA8B,KAATD,KAC1CnB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAIyB,SAAUN,GAClBD,EAAMQ,YACVzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAE5C1B,EAAM,IAAMA,IAEZA,EAAMD,EAAEyB,SAAUN,GACZnB,GAAMkB,EAAMQ,UAENR,EAAMQ,YACjBzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAF3C1B,EAAM,GAIFiB,EAAMU,OACV3B,EAAMiB,EAAMU,KAAO3B,IAGP,KAATkB,IACCD,EAAMW,YACV5B,EAAM,KAAOA,GAEdA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,IAEJ,IAATkB,GACCD,EAAMW,WAAiC,MAApB5B,EAAI8B,OAAQ,KACnC9B,EAAM,IAAMA,GAGPA,CACR,CC3EA,SAAS+B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCXA,IAAIoC,EAAMC,KAAKD,IACXtB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BmB,EAAUvB,OAAOC,UAAUsB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAazB,SAASC,EAAczB,GACtB,IAAI0B,EACA3C,EACA4C,EAAIC,WAAY5B,EAAMG,KAC1B,IAAME,SAAUsB,GAAM,CACrB,IAAMjD,EAAUsB,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2CvB,GAG7D4C,EAAI3B,EAAMG,GACV,CACD,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJnB,EAAM4C,EAAEE,cAAe7B,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJzB,EAAM4C,EAAEG,QAAS9B,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCO,EAAKY,GAAM,OACfD,EAAS1B,EAAMQ,WACD,IACbkB,GAAU,GAEX3C,EAAM4C,EAAEE,cAAeH,IAEvB3C,EAAM4C,EAAEI,YAAa/B,EAAMQ,WAEtBR,EAAMW,YACX5B,EAAMkC,EAAQL,KAAM7B,EAAKyC,EAAoB,OAC7CzC,EAAMkC,EAAQL,KAAM7B,EAAKwC,EAAoB,KAC7CxC,EAAMkC,EAAQL,KAAM7B,EAAKuC,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIhB,MAAO,mCAAqCN,EAAME,WAc7D,OAZAnB,EAAMkC,EAAQL,KAAM7B,EAAKmC,EAAmB,SAC5CnC,EAAMkC,EAAQL,KAAM7B,EAAKoC,EAAmB,SACvCnB,EAAMW,YACV5B,EAAMkC,EAAQL,KAAM7B,EAAKqC,EAAgB,OACzCrC,EAAMkC,EAAQL,KAAM7B,EAAKsC,EAAsB,SAE3CM,GAAK,GAAK3B,EAAMU,OACpB3B,EAAMiB,EAAMU,KAAO3B,GAEpBA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,EAElB,CC5EA,SAASiD,EAAQnD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASkD,EAAUhD,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAM+C,EAAQ3C,GACd2C,EAAQ3C,GAAQJ,CAElB,CC5BA,IAAIiD,EAAexC,OAAOwC,aACtBC,EAAQC,MACRC,EAAUC,MAAMD,QAYpB,SAASE,EAAYvC,GACpB,IAAIjB,EAAM,CAAA,EAMV,OALAA,EAAImB,UAAYF,EAAME,UACtBnB,EAAIyB,eAAkC,IAApBR,EAAMQ,UAAyB,EAAIR,EAAMQ,UAC3DzB,EAAIG,MAAQc,EAAMd,MAClBH,EAAIyD,MAAQxC,EAAMwC,OAAS,GAC3BzD,EAAI0D,QAAUzC,EAAMyC,QACb1D,CACR,CAmBA,SAAS2D,EAAmBC,GAC3B,IAAIC,EACAJ,EACAxC,EACA6C,EACAC,EACA/D,EACAgE,EACAjE,EACAkE,EAEJ,IAAMX,EAASM,GACd,MAAM,IAAIM,UAAW,8DAAgEN,EAAS,MAI/F,IAFA5D,EAAM,GACNgE,EAAM,EACAjE,EAAI,EAAGA,EAAI6D,EAAOrD,OAAQR,IAE/B,GAAKgC,EADLd,EAAQ2C,EAAQ7D,IAEfC,GAAOiB,MACD,CAGN,GAFA4C,OAAgC,IAApB5C,EAAMQ,YAClBR,EAAQuC,EAAYvC,IACRE,UACX,MAAM,IAAI+C,UAAW,oEAAqEnE,EAAG,cAAgBkB,EAAQ,MAMtH,IAJKA,EAAMyC,UACVM,EAAM/C,EAAMyC,SAEbD,EAAQxC,EAAMwC,MACRQ,EAAI,EAAGA,EAAIR,EAAMlD,OAAQ0D,IAE9B,OADAH,EAAOL,EAAM3B,OAAQmC,IAErB,IAAK,IACJhD,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAMkD,UAAW,EACjB,MACD,IAAK,IACJlD,EAAMkD,SAAWV,EAAMW,QAAS,KAAQ,EACxC,MACD,IAAK,IACJnD,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBuC,GAGtC,GAAqB,MAAhB7C,EAAMd,MAAgB,CAG1B,GAFAc,EAAMd,MAAQkB,SAAUgD,UAAWL,GAAO,IAC1CA,GAAO,EACFZ,EAAOnC,EAAMd,OACjB,MAAM,IAAI+D,UAAW,wCAA0CF,EAAM,6BAA+B/C,EAAMd,MAAQ,MAE9Gc,EAAMd,MAAQ,IAClBc,EAAMS,UAAW,EACjBT,EAAMd,OAASc,EAAMd,MAEtB,CACD,GAAK0D,GACqB,MAApB5C,EAAMQ,UAAoB,CAG9B,GAFAR,EAAMQ,UAAYJ,SAAUgD,UAAWL,GAAO,IAC9CA,GAAO,EACFZ,EAAOnC,EAAMQ,WACjB,MAAM,IAAIyC,UAAW,4CAA8CF,EAAM,6BAA+B/C,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBoC,GAAY,EAEb,CAGF,OADA5C,EAAMG,IAAMiD,UAAWL,GACd/C,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEC0C,IACJ5C,EAAMkD,UAAW,GAElBlD,EAAMG,IAAMJ,EAAeC,GAC3B,MACD,IAAK,IAEJA,EAAMqD,SAAW,EAAgBrD,EAAMQ,WAAa,EACpD,MACD,IAAK,IAEJ,IAAM2B,EAAOnC,EAAMG,KAAQ,CAE1B,IADA2C,EAAM1C,SAAUJ,EAAMG,IAAK,KAChB,GAAK2C,EAAM,IACrB,MAAM,IAAIxC,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgC,EAAOW,GACpBpD,OAAQM,EAAMG,KACd+B,EAAcY,EACf,CACD,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEEF,IACL5C,EAAMQ,UAAY,GAEnBR,EAAMG,IAAMsB,EAAczB,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAMqD,UAAY,GAAKrD,EAAMG,IAAIb,OAASU,EAAMqD,WACpDrD,EAAMG,IAAMH,EAAMG,IAAImD,UAAW,EAAGtD,EAAMqD,WAEtCrD,EAAMkD,SACVlD,EAAMG,IAAMnB,EAASgB,EAAMG,IAAKH,EAAMd,OAASc,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMd,QACjBc,EAAMG,IAAM8B,EAAUjC,EAAMG,IAAKH,EAAMd,MAAOc,EAAMS,WAErD1B,GAAOiB,EAAMG,KAAO,GACpB4C,GAAO,CACP,CAEF,OAAOhE,CACR,CC3LA,IAAIwE,EAAK,6EAYT,SAASC,EAAOC,GACf,IAAIzD,EAAQ,CACXyC,QAAagB,EAAO,GAAQrD,SAAUqD,EAAO,GAAK,SAAO,EACzDjB,MAASiB,EAAO,GAChBvE,MAASuE,EAAO,GAChBjD,UAAaiD,EAAO,GACpBvD,UAAauD,EAAO,IAKrB,MAHoB,MAAfA,EAAO,SAA8B,IAAfA,EAAO,KACjCzD,EAAMQ,UAAY,KAEZR,CACR,CAeA,SAAS0D,EAAgBzE,GACxB,IAAI0E,EACAhB,EACAc,EACAG,EAKJ,IAHAjB,EAAS,GACTiB,EAAO,EACPH,EAAQF,EAAGM,KAAM5E,GACTwE,IACPE,EAAU1E,EAAI6E,MAAOF,EAAML,EAAGQ,UAAYN,EAAO,GAAInE,SACxCA,QACZqD,EAAOqB,KAAML,GAEdhB,EAAOqB,KAAMR,EAAOC,IACpBG,EAAOL,EAAGQ,UACVN,EAAQF,EAAGM,KAAM5E,GAMlB,OAJA0E,EAAU1E,EAAI6E,MAAOF,IACRtE,QACZqD,EAAOqB,KAAML,GAEPhB,CACR,CClDA,SAAS7B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCUA,SAASsF,EAAQhF,GAChB,IAAI0D,EACAuB,EACApF,EAEJ,IAAMgC,EAAU7B,GACf,MAAM,IAAIgE,UAAWgB,EAAQ,kEAAmEhF,IAKjG,IAHA0D,EAASwB,EAAUlF,IACnBiF,EAAO,IAAI5B,MAAOc,UAAU9D,SACtB,GAAMqD,EACN7D,EAAI,EAAGA,EAAIoF,EAAK5E,OAAQR,IAC7BoF,EAAMpF,GAAMsE,UAAWtE,GAExB,OAAOsF,EAAYC,MAAO,KAAMH,EACjC,QCkEA,WACC,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EACAlE,EASJ,IANAwF,EAAUlB,UAAW,GACrBmB,EAASnB,UAAW,GAGpBoB,GADAG,EAAQvB,UAAW,GADnBsB,GAHAD,EAAQrB,UAAW,IAGL9D,UAECA,OACfuF,EAAMN,EACAzF,EAAI,EAAGA,EAAI4F,EAAO5F,IAAM,CAI7B,GAHAgG,EAAIL,EAAO3F,GACXkE,EAAII,UAAWtE,EAAE,GAEH,WADd8F,EAAOD,EAAO7F,EAAE0F,IAEVxB,EAAI,EACRA,EAAI,EACOA,GAAK8B,IAChB9B,EAAI8B,EAAI,QAEH,GAAc,SAATF,EACN5B,EAAI,GACRA,GAAK8B,GACI,GAEG,IADX9B,GAAK8B,KAEJ9B,GAAK8B,GAGI9B,GAAK8B,IAChB9B,GAAK8B,IACKA,IACT9B,GAAK8B,QAOP,GAHc,cAATF,GAAwB5B,EAAI,IAChCA,GAAK8B,GAED9B,EAAI,GAAKA,GAAK8B,EAClB,MAAM,IAAIE,WAAYf,EAAQ,+FAAgGnF,EAAGkE,KAGnI+B,EAAIT,EAASxF,IAGJ,GAAgB,IAAXyF,EACbM,GAAO7B,EAAI+B,EAEXF,GAAO7B,EAAI+B,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 3188d51..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,r;e=this,r=function(){"use strict";function e(e){return"number"==typeof e}function r(e){var r,i="";for(r=0;r0&&(i-=1),a=n.toExponential(i)):a=n.toPrecision(r.precision),r.alternate||(a=l.call(a,b,"$1e"),a=l.call(a,w,"e"),a=l.call(a,h,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return a=l.call(a,f,"e+0$1"),a=l.call(a,g,"e-0$1"),r.alternate&&(a=l.call(a,u,"$1."),a=l.call(a,d,"$1.e")),n>=0&&r.sign&&(a=r.sign+a),a=r.specifier===p.call(r.specifier)?p.call(a):c.call(a)}function v(e){var r,i="";for(r=0;r127)throw new Error("invalid character code. Value: "+n.arg);n.arg=k(c)?String(n.arg):x(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":r||(n.precision=6),n.arg=m(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=y(n.arg,n.width,n.padRight)),p+=n.arg||"",l+=1}return p}var $=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function F(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function I(e){var r,i,a,n;for(i=[],n=0,a=$.exec(e);a;)(r=e.slice(n,$.lastIndex-a[0].length)).length&&i.push(r),i.push(F(a)),n=$.lastIndex,a=$.exec(e);return(r=e.slice(n)).length&&i.push(r),i}function T(e){return"string"==typeof e}function R(e){var r,i,a;if(!T(e))throw new TypeError(R("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=I(e),(i=new Array(arguments.length))[0]=r,a=1;a=c&&(l=c-1);else if("wrap"===s)l<0?(l+=c)<0&&0!=(l%=c)&&(l+=c):l>=c&&(l-=c)>=c&&(l%=c);else if("normalize"===s&&l<0&&(l+=c),l<0||l>=c)throw new RangeError(R("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",f,l));(p=e[f])<0&&0===r?o-=l*p:o+=l*p}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=r(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index c53e67e..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js","../node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js","../node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js","../node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/main.js","../node_modules/@stdlib/string-base-format-tokenize/lib/main.js","../node_modules/@stdlib/string-format/lib/is_string.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\nimport zeroPad from './zero_pad.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport formatInteger from './format_integer.js';\nimport isString from './is_string.js';\nimport formatDouble from './format_double.js';\nimport spacePad from './space_pad.js';\nimport zeroPad from './zero_pad.js';\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\nvar isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.\n\n\n// FUNCTIONS //\n\n/**\n* Initializes token object with properties of supplied format identifier object or default values if not present.\n*\n* @private\n* @param {Object} token - format identifier object\n* @returns {Object} token object\n*/\nfunction initialize( token ) {\n\tvar out = {};\n\tout.specifier = token.specifier;\n\tout.precision = ( token.precision === void 0 ) ? 1 : token.precision;\n\tout.width = token.width;\n\tout.flags = token.flags || '';\n\tout.mapping = token.mapping;\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Generates string from a token array by interpolating values.\n*\n* @param {Array} tokens - string parts and format identifier objects\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be an array\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var tokens = [ 'beep ', { 'specifier': 's' } ];\n* var out = formatInterpolate( tokens, 'boop' );\n* // returns 'beep boop'\n*/\nfunction formatInterpolate( tokens ) {\n\tvar hasPeriod;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isArray( tokens ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );\n\t}\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\thasPeriod = token.precision !== void 0;\n\t\t\ttoken = initialize( token );\n\t\t\tif ( !token.specifier ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );\n\t\t\t}\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasPeriod ) {\n\t\t\t\tif ( token.precision === '*' ) {\n\t\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t\t}\n\t\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\t\thasPeriod = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInterpolate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\tvar token = {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n\tif ( match[ 4 ] === '.' && match[ 5 ] === void 0 ) {\n\t\ttoken.precision = '1';\n\t}\n\treturn token;\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string into an array of string parts and format identifier objects.\n*\n* @param {string} str - input string\n* @returns {Array} tokens\n*\n* @example\n* var tokens = formatTokenize( 'Hello %s!' );\n* // returns [ 'Hello ', {...}, '!' ]\n*/\nfunction formatTokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nexport default formatTokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport interpolate from '@stdlib/string-base-format-interpolate';\nimport tokenize from '@stdlib/string-base-format-tokenize';\nimport isString from './is_string.js';\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default format;\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 format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["isNumber","value","zeros","n","i","out","zeroPad","str","width","right","negative","pad","length","startsWithMinus","substr","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","formatInteger","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","isString","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","spaces","spacePad","fromCharCode","isnan","isNaN","isArray","Array","initialize","flags","mapping","formatInterpolate","tokens","hasPeriod","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","RE","parse","match","formatTokenize","content","prev","exec","slice","lastIndex","push","format","args","tokenize","interpolate","apply","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","RangeError"],"mappings":";yCAsCA,SAASA,EAAUC,GAClB,MAA0B,iBAAVA,CACjB,CCAA,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASC,EAASC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,EACb,CAoCMM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,CAaT,CCpDA,IAAIQ,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAajC,SAASC,EAAeC,GACvB,IAAIC,EACAlB,EACAD,EAEJ,OAASkB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAlB,EAAMiB,EAAMG,IACZrB,EAAIsB,SAAUrB,EAAK,KACbsB,SAAUvB,GAAM,CACrB,IAAMJ,EAAUK,GACf,MAAM,IAAIuB,MAAO,2BAA6BvB,GAE/CD,EAAI,CACJ,CAkCD,OAjCKA,EAAI,IAA2B,MAApBkB,EAAME,WAA8B,KAATD,KAC1CnB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAIyB,SAAUN,GAClBD,EAAMQ,YACVzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAE5C1B,EAAM,IAAMA,IAEZA,EAAMD,EAAEyB,SAAUN,GACZnB,GAAMkB,EAAMQ,UAENR,EAAMQ,YACjBzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAF3C1B,EAAM,GAIFiB,EAAMU,OACV3B,EAAMiB,EAAMU,KAAO3B,IAGP,KAATkB,IACCD,EAAMW,YACV5B,EAAM,KAAOA,GAEdA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,IAEJ,IAATkB,GACCD,EAAMW,WAAiC,MAApB5B,EAAI8B,OAAQ,KACnC9B,EAAM,IAAMA,GAGPA,CACR,CC3EA,SAAS+B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCXA,IAAIoC,EAAMC,KAAKD,IACXtB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BmB,EAAUvB,OAAOC,UAAUsB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAazB,SAASC,EAAczB,GACtB,IAAI0B,EACA3C,EACA4C,EAAIC,WAAY5B,EAAMG,KAC1B,IAAME,SAAUsB,GAAM,CACrB,IAAMjD,EAAUsB,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2CvB,GAG7D4C,EAAI3B,EAAMG,GACV,CACD,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJnB,EAAM4C,EAAEE,cAAe7B,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJzB,EAAM4C,EAAEG,QAAS9B,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCO,EAAKY,GAAM,OACfD,EAAS1B,EAAMQ,WACD,IACbkB,GAAU,GAEX3C,EAAM4C,EAAEE,cAAeH,IAEvB3C,EAAM4C,EAAEI,YAAa/B,EAAMQ,WAEtBR,EAAMW,YACX5B,EAAMkC,EAAQL,KAAM7B,EAAKyC,EAAoB,OAC7CzC,EAAMkC,EAAQL,KAAM7B,EAAKwC,EAAoB,KAC7CxC,EAAMkC,EAAQL,KAAM7B,EAAKuC,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIhB,MAAO,mCAAqCN,EAAME,WAc7D,OAZAnB,EAAMkC,EAAQL,KAAM7B,EAAKmC,EAAmB,SAC5CnC,EAAMkC,EAAQL,KAAM7B,EAAKoC,EAAmB,SACvCnB,EAAMW,YACV5B,EAAMkC,EAAQL,KAAM7B,EAAKqC,EAAgB,OACzCrC,EAAMkC,EAAQL,KAAM7B,EAAKsC,EAAsB,SAE3CM,GAAK,GAAK3B,EAAMU,OACpB3B,EAAMiB,EAAMU,KAAO3B,GAEpBA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,EAElB,CC5EA,SAASiD,EAAQnD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASkD,EAAUhD,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAM+C,EAAQ3C,GACd2C,EAAQ3C,GAAQJ,CAElB,CC5BA,IAAIiD,EAAexC,OAAOwC,aACtBC,EAAQC,MACRC,EAAUC,MAAMD,QAYpB,SAASE,EAAYvC,GACpB,IAAIjB,EAAM,CAAA,EAMV,OALAA,EAAImB,UAAYF,EAAME,UACtBnB,EAAIyB,eAAkC,IAApBR,EAAMQ,UAAyB,EAAIR,EAAMQ,UAC3DzB,EAAIG,MAAQc,EAAMd,MAClBH,EAAIyD,MAAQxC,EAAMwC,OAAS,GAC3BzD,EAAI0D,QAAUzC,EAAMyC,QACb1D,CACR,CAmBA,SAAS2D,EAAmBC,GAC3B,IAAIC,EACAJ,EACAxC,EACA6C,EACAC,EACA/D,EACAgE,EACAjE,EACAkE,EAEJ,IAAMX,EAASM,GACd,MAAM,IAAIM,UAAW,8DAAgEN,EAAS,MAI/F,IAFA5D,EAAM,GACNgE,EAAM,EACAjE,EAAI,EAAGA,EAAI6D,EAAOrD,OAAQR,IAE/B,GAAKgC,EADLd,EAAQ2C,EAAQ7D,IAEfC,GAAOiB,MACD,CAGN,GAFA4C,OAAgC,IAApB5C,EAAMQ,YAClBR,EAAQuC,EAAYvC,IACRE,UACX,MAAM,IAAI+C,UAAW,oEAAqEnE,EAAG,cAAgBkB,EAAQ,MAMtH,IAJKA,EAAMyC,UACVM,EAAM/C,EAAMyC,SAEbD,EAAQxC,EAAMwC,MACRQ,EAAI,EAAGA,EAAIR,EAAMlD,OAAQ0D,IAE9B,OADAH,EAAOL,EAAM3B,OAAQmC,IAErB,IAAK,IACJhD,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAMkD,UAAW,EACjB,MACD,IAAK,IACJlD,EAAMkD,SAAWV,EAAMW,QAAS,KAAQ,EACxC,MACD,IAAK,IACJnD,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBuC,GAGtC,GAAqB,MAAhB7C,EAAMd,MAAgB,CAG1B,GAFAc,EAAMd,MAAQkB,SAAUgD,UAAWL,GAAO,IAC1CA,GAAO,EACFZ,EAAOnC,EAAMd,OACjB,MAAM,IAAI+D,UAAW,wCAA0CF,EAAM,6BAA+B/C,EAAMd,MAAQ,MAE9Gc,EAAMd,MAAQ,IAClBc,EAAMS,UAAW,EACjBT,EAAMd,OAASc,EAAMd,MAEtB,CACD,GAAK0D,GACqB,MAApB5C,EAAMQ,UAAoB,CAG9B,GAFAR,EAAMQ,UAAYJ,SAAUgD,UAAWL,GAAO,IAC9CA,GAAO,EACFZ,EAAOnC,EAAMQ,WACjB,MAAM,IAAIyC,UAAW,4CAA8CF,EAAM,6BAA+B/C,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBoC,GAAY,EAEb,CAGF,OADA5C,EAAMG,IAAMiD,UAAWL,GACd/C,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEC0C,IACJ5C,EAAMkD,UAAW,GAElBlD,EAAMG,IAAMJ,EAAeC,GAC3B,MACD,IAAK,IAEJA,EAAMqD,SAAW,EAAgBrD,EAAMQ,WAAa,EACpD,MACD,IAAK,IAEJ,IAAM2B,EAAOnC,EAAMG,KAAQ,CAE1B,IADA2C,EAAM1C,SAAUJ,EAAMG,IAAK,KAChB,GAAK2C,EAAM,IACrB,MAAM,IAAIxC,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgC,EAAOW,GACpBpD,OAAQM,EAAMG,KACd+B,EAAcY,EACf,CACD,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEEF,IACL5C,EAAMQ,UAAY,GAEnBR,EAAMG,IAAMsB,EAAczB,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAMqD,UAAY,GAAKrD,EAAMG,IAAIb,OAASU,EAAMqD,WACpDrD,EAAMG,IAAMH,EAAMG,IAAImD,UAAW,EAAGtD,EAAMqD,WAEtCrD,EAAMkD,SACVlD,EAAMG,IAAMnB,EAASgB,EAAMG,IAAKH,EAAMd,OAASc,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMd,QACjBc,EAAMG,IAAM8B,EAAUjC,EAAMG,IAAKH,EAAMd,MAAOc,EAAMS,WAErD1B,GAAOiB,EAAMG,KAAO,GACpB4C,GAAO,CACP,CAEF,OAAOhE,CACR,CC3LA,IAAIwE,EAAK,6EAYT,SAASC,EAAOC,GACf,IAAIzD,EAAQ,CACXyC,QAAagB,EAAO,GAAQrD,SAAUqD,EAAO,GAAK,SAAO,EACzDjB,MAASiB,EAAO,GAChBvE,MAASuE,EAAO,GAChBjD,UAAaiD,EAAO,GACpBvD,UAAauD,EAAO,IAKrB,MAHoB,MAAfA,EAAO,SAA8B,IAAfA,EAAO,KACjCzD,EAAMQ,UAAY,KAEZR,CACR,CAeA,SAAS0D,EAAgBzE,GACxB,IAAI0E,EACAhB,EACAc,EACAG,EAKJ,IAHAjB,EAAS,GACTiB,EAAO,EACPH,EAAQF,EAAGM,KAAM5E,GACTwE,IACPE,EAAU1E,EAAI6E,MAAOF,EAAML,EAAGQ,UAAYN,EAAO,GAAInE,SACxCA,QACZqD,EAAOqB,KAAML,GAEdhB,EAAOqB,KAAMR,EAAOC,IACpBG,EAAOL,EAAGQ,UACVN,EAAQF,EAAGM,KAAM5E,GAMlB,OAJA0E,EAAU1E,EAAI6E,MAAOF,IACRtE,QACZqD,EAAOqB,KAAML,GAEPhB,CACR,CClDA,SAAS7B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCUA,SAASsF,EAAQhF,GAChB,IAAI0D,EACAuB,EACApF,EAEJ,IAAMgC,EAAU7B,GACf,MAAM,IAAIgE,UAAWgB,EAAQ,kEAAmEhF,IAKjG,IAHA0D,EAASwB,EAAUlF,IACnBiF,EAAO,IAAI5B,MAAOc,UAAU9D,SACtB,GAAMqD,EACN7D,EAAI,EAAGA,EAAIoF,EAAK5E,OAAQR,IAC7BoF,EAAMpF,GAAMsE,UAAWtE,GAExB,OAAOsF,EAAYC,MAAO,KAAMH,EACjC,QCkEA,WACC,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EACAlE,EASJ,IANAwF,EAAUlB,UAAW,GACrBmB,EAASnB,UAAW,GAGpBoB,GADAG,EAAQvB,UAAW,GADnBsB,GAHAD,EAAQrB,UAAW,IAGL9D,UAECA,OACfuF,EAAMN,EACAzF,EAAI,EAAGA,EAAI4F,EAAO5F,IAAM,CAI7B,GAHAgG,EAAIL,EAAO3F,GACXkE,EAAII,UAAWtE,EAAE,GAEH,WADd8F,EAAOD,EAAO7F,EAAE0F,IAEVxB,EAAI,EACRA,EAAI,EACOA,GAAK8B,IAChB9B,EAAI8B,EAAI,QAEH,GAAc,SAATF,EACN5B,EAAI,GACRA,GAAK8B,GACI,GAEG,IADX9B,GAAK8B,KAEJ9B,GAAK8B,GAGI9B,GAAK8B,IAChB9B,GAAK8B,IACKA,IACT9B,GAAK8B,QAOP,GAHc,cAATF,GAAwB5B,EAAI,IAChCA,GAAK8B,GAED9B,EAAI,GAAKA,GAAK8B,EAClB,MAAM,IAAIE,WAAYf,EAAQ,+FAAgGnF,EAAGkE,KAGnI+B,EAAIT,EAASxF,IAGJ,GAAgB,IAAXyF,EACbM,GAAO7B,EAAI+B,EAEXF,GAAO7B,EAAI+B,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index af41e62..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 97e9fec..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7a7e0db0aa513c1b145cb83c71e34de3f7f970c7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 04:41:47 +0000 Subject: [PATCH 083/140] 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 | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 63 +- src/main.c | 110 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 12402 insertions(+), 6135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 59d1175..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T01:27:24.812Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 f0db682..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ade6523 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,r;e=this,r=function(){"use strict";function e(e){return"number"==typeof e}function r(e){var r,i="";for(r=0;r0&&(i-=1),a=n.toExponential(i)):a=n.toPrecision(r.precision),r.alternate||(a=l.call(a,b,"$1e"),a=l.call(a,w,"e"),a=l.call(a,h,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return a=l.call(a,f,"e+0$1"),a=l.call(a,g,"e-0$1"),r.alternate&&(a=l.call(a,u,"$1."),a=l.call(a,d,"$1.e")),n>=0&&r.sign&&(a=r.sign+a),a=r.specifier===p.call(r.specifier)?p.call(a):c.call(a)}function v(e){var r,i="";for(r=0;r127)throw new Error("invalid character code. Value: "+n.arg);n.arg=k(c)?String(n.arg):x(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":r||(n.precision=6),n.arg=m(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=y(n.arg,n.width,n.padRight)),p+=n.arg||"",l+=1}return p}var $=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function F(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function I(e){var r,i,a,n;for(i=[],n=0,a=$.exec(e);a;)(r=e.slice(n,$.lastIndex-a[0].length)).length&&i.push(r),i.push(F(a)),n=$.lastIndex,a=$.exec(e);return(r=e.slice(n)).length&&i.push(r),i}function T(e){return"string"==typeof e}function R(e){var r,i,a;if(!T(e))throw new TypeError(R("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=I(e),(i=new Array(arguments.length))[0]=r,a=1;a=c&&(l=c-1);else if("wrap"===s)l<0?(l+=c)<0&&0!=(l%=c)&&(l+=c):l>=c&&(l-=c)>=c&&(l%=c);else if("normalize"===s&&l<0&&(l+=c),l<0||l>=c)throw new RangeError(R("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",f,l));(p=e[f])<0&&0===r?o-=l*p:o+=l*p}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=r(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..241296b --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js","../node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js","../node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js","../node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/main.js","../node_modules/@stdlib/string-base-format-tokenize/lib/main.js","../node_modules/@stdlib/string-format/lib/is_string.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\nimport zeroPad from './zero_pad.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport formatInteger from './format_integer.js';\nimport isString from './is_string.js';\nimport formatDouble from './format_double.js';\nimport spacePad from './space_pad.js';\nimport zeroPad from './zero_pad.js';\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\nvar isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.\n\n\n// FUNCTIONS //\n\n/**\n* Initializes token object with properties of supplied format identifier object or default values if not present.\n*\n* @private\n* @param {Object} token - format identifier object\n* @returns {Object} token object\n*/\nfunction initialize( token ) {\n\tvar out = {};\n\tout.specifier = token.specifier;\n\tout.precision = ( token.precision === void 0 ) ? 1 : token.precision;\n\tout.width = token.width;\n\tout.flags = token.flags || '';\n\tout.mapping = token.mapping;\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Generates string from a token array by interpolating values.\n*\n* @param {Array} tokens - string parts and format identifier objects\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be an array\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var tokens = [ 'beep ', { 'specifier': 's' } ];\n* var out = formatInterpolate( tokens, 'boop' );\n* // returns 'beep boop'\n*/\nfunction formatInterpolate( tokens ) {\n\tvar hasPeriod;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isArray( tokens ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );\n\t}\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\thasPeriod = token.precision !== void 0;\n\t\t\ttoken = initialize( token );\n\t\t\tif ( !token.specifier ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );\n\t\t\t}\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasPeriod ) {\n\t\t\t\tif ( token.precision === '*' ) {\n\t\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t\t}\n\t\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\t\thasPeriod = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInterpolate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\tvar token = {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n\tif ( match[ 4 ] === '.' && match[ 5 ] === void 0 ) {\n\t\ttoken.precision = '1';\n\t}\n\treturn token;\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string into an array of string parts and format identifier objects.\n*\n* @param {string} str - input string\n* @returns {Array} tokens\n*\n* @example\n* var tokens = formatTokenize( 'Hello %s!' );\n* // returns [ 'Hello ', {...}, '!' ]\n*/\nfunction formatTokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nexport default formatTokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport interpolate from '@stdlib/string-base-format-interpolate';\nimport tokenize from '@stdlib/string-base-format-tokenize';\nimport isString from './is_string.js';\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default format;\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 format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["isNumber","value","zeros","n","i","out","zeroPad","str","width","right","negative","pad","length","startsWithMinus","substr","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","formatInteger","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","isString","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","spaces","spacePad","fromCharCode","isnan","isNaN","isArray","Array","initialize","flags","mapping","formatInterpolate","tokens","hasPeriod","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","RE","parse","match","formatTokenize","content","prev","exec","slice","lastIndex","push","format","args","tokenize","interpolate","apply","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","RangeError"],"mappings":";yCAsCA,SAASA,EAAUC,GAClB,MAA0B,iBAAVA,CACjB,CCAA,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASC,EAASC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,EACb,CAoCMM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,CAaT,CCpDA,IAAIQ,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAajC,SAASC,EAAeC,GACvB,IAAIC,EACAlB,EACAD,EAEJ,OAASkB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAlB,EAAMiB,EAAMG,IACZrB,EAAIsB,SAAUrB,EAAK,KACbsB,SAAUvB,GAAM,CACrB,IAAMJ,EAAUK,GACf,MAAM,IAAIuB,MAAO,2BAA6BvB,GAE/CD,EAAI,CACJ,CAkCD,OAjCKA,EAAI,IAA2B,MAApBkB,EAAME,WAA8B,KAATD,KAC1CnB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAIyB,SAAUN,GAClBD,EAAMQ,YACVzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAE5C1B,EAAM,IAAMA,IAEZA,EAAMD,EAAEyB,SAAUN,GACZnB,GAAMkB,EAAMQ,UAENR,EAAMQ,YACjBzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAF3C1B,EAAM,GAIFiB,EAAMU,OACV3B,EAAMiB,EAAMU,KAAO3B,IAGP,KAATkB,IACCD,EAAMW,YACV5B,EAAM,KAAOA,GAEdA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,IAEJ,IAATkB,GACCD,EAAMW,WAAiC,MAApB5B,EAAI8B,OAAQ,KACnC9B,EAAM,IAAMA,GAGPA,CACR,CC3EA,SAAS+B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCXA,IAAIoC,EAAMC,KAAKD,IACXtB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BmB,EAAUvB,OAAOC,UAAUsB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAazB,SAASC,EAAczB,GACtB,IAAI0B,EACA3C,EACA4C,EAAIC,WAAY5B,EAAMG,KAC1B,IAAME,SAAUsB,GAAM,CACrB,IAAMjD,EAAUsB,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2CvB,GAG7D4C,EAAI3B,EAAMG,GACV,CACD,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJnB,EAAM4C,EAAEE,cAAe7B,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJzB,EAAM4C,EAAEG,QAAS9B,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCO,EAAKY,GAAM,OACfD,EAAS1B,EAAMQ,WACD,IACbkB,GAAU,GAEX3C,EAAM4C,EAAEE,cAAeH,IAEvB3C,EAAM4C,EAAEI,YAAa/B,EAAMQ,WAEtBR,EAAMW,YACX5B,EAAMkC,EAAQL,KAAM7B,EAAKyC,EAAoB,OAC7CzC,EAAMkC,EAAQL,KAAM7B,EAAKwC,EAAoB,KAC7CxC,EAAMkC,EAAQL,KAAM7B,EAAKuC,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIhB,MAAO,mCAAqCN,EAAME,WAc7D,OAZAnB,EAAMkC,EAAQL,KAAM7B,EAAKmC,EAAmB,SAC5CnC,EAAMkC,EAAQL,KAAM7B,EAAKoC,EAAmB,SACvCnB,EAAMW,YACV5B,EAAMkC,EAAQL,KAAM7B,EAAKqC,EAAgB,OACzCrC,EAAMkC,EAAQL,KAAM7B,EAAKsC,EAAsB,SAE3CM,GAAK,GAAK3B,EAAMU,OACpB3B,EAAMiB,EAAMU,KAAO3B,GAEpBA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,EAElB,CC5EA,SAASiD,EAAQnD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASkD,EAAUhD,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAM+C,EAAQ3C,GACd2C,EAAQ3C,GAAQJ,CAElB,CC5BA,IAAIiD,EAAexC,OAAOwC,aACtBC,EAAQC,MACRC,EAAUC,MAAMD,QAYpB,SAASE,EAAYvC,GACpB,IAAIjB,EAAM,CAAA,EAMV,OALAA,EAAImB,UAAYF,EAAME,UACtBnB,EAAIyB,eAAkC,IAApBR,EAAMQ,UAAyB,EAAIR,EAAMQ,UAC3DzB,EAAIG,MAAQc,EAAMd,MAClBH,EAAIyD,MAAQxC,EAAMwC,OAAS,GAC3BzD,EAAI0D,QAAUzC,EAAMyC,QACb1D,CACR,CAmBA,SAAS2D,EAAmBC,GAC3B,IAAIC,EACAJ,EACAxC,EACA6C,EACAC,EACA/D,EACAgE,EACAjE,EACAkE,EAEJ,IAAMX,EAASM,GACd,MAAM,IAAIM,UAAW,8DAAgEN,EAAS,MAI/F,IAFA5D,EAAM,GACNgE,EAAM,EACAjE,EAAI,EAAGA,EAAI6D,EAAOrD,OAAQR,IAE/B,GAAKgC,EADLd,EAAQ2C,EAAQ7D,IAEfC,GAAOiB,MACD,CAGN,GAFA4C,OAAgC,IAApB5C,EAAMQ,YAClBR,EAAQuC,EAAYvC,IACRE,UACX,MAAM,IAAI+C,UAAW,oEAAqEnE,EAAG,cAAgBkB,EAAQ,MAMtH,IAJKA,EAAMyC,UACVM,EAAM/C,EAAMyC,SAEbD,EAAQxC,EAAMwC,MACRQ,EAAI,EAAGA,EAAIR,EAAMlD,OAAQ0D,IAE9B,OADAH,EAAOL,EAAM3B,OAAQmC,IAErB,IAAK,IACJhD,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAMkD,UAAW,EACjB,MACD,IAAK,IACJlD,EAAMkD,SAAWV,EAAMW,QAAS,KAAQ,EACxC,MACD,IAAK,IACJnD,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBuC,GAGtC,GAAqB,MAAhB7C,EAAMd,MAAgB,CAG1B,GAFAc,EAAMd,MAAQkB,SAAUgD,UAAWL,GAAO,IAC1CA,GAAO,EACFZ,EAAOnC,EAAMd,OACjB,MAAM,IAAI+D,UAAW,wCAA0CF,EAAM,6BAA+B/C,EAAMd,MAAQ,MAE9Gc,EAAMd,MAAQ,IAClBc,EAAMS,UAAW,EACjBT,EAAMd,OAASc,EAAMd,MAEtB,CACD,GAAK0D,GACqB,MAApB5C,EAAMQ,UAAoB,CAG9B,GAFAR,EAAMQ,UAAYJ,SAAUgD,UAAWL,GAAO,IAC9CA,GAAO,EACFZ,EAAOnC,EAAMQ,WACjB,MAAM,IAAIyC,UAAW,4CAA8CF,EAAM,6BAA+B/C,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBoC,GAAY,EAEb,CAGF,OADA5C,EAAMG,IAAMiD,UAAWL,GACd/C,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEC0C,IACJ5C,EAAMkD,UAAW,GAElBlD,EAAMG,IAAMJ,EAAeC,GAC3B,MACD,IAAK,IAEJA,EAAMqD,SAAW,EAAgBrD,EAAMQ,WAAa,EACpD,MACD,IAAK,IAEJ,IAAM2B,EAAOnC,EAAMG,KAAQ,CAE1B,IADA2C,EAAM1C,SAAUJ,EAAMG,IAAK,KAChB,GAAK2C,EAAM,IACrB,MAAM,IAAIxC,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgC,EAAOW,GACpBpD,OAAQM,EAAMG,KACd+B,EAAcY,EACf,CACD,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEEF,IACL5C,EAAMQ,UAAY,GAEnBR,EAAMG,IAAMsB,EAAczB,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAMqD,UAAY,GAAKrD,EAAMG,IAAIb,OAASU,EAAMqD,WACpDrD,EAAMG,IAAMH,EAAMG,IAAImD,UAAW,EAAGtD,EAAMqD,WAEtCrD,EAAMkD,SACVlD,EAAMG,IAAMnB,EAASgB,EAAMG,IAAKH,EAAMd,OAASc,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMd,QACjBc,EAAMG,IAAM8B,EAAUjC,EAAMG,IAAKH,EAAMd,MAAOc,EAAMS,WAErD1B,GAAOiB,EAAMG,KAAO,GACpB4C,GAAO,CACP,CAEF,OAAOhE,CACR,CC3LA,IAAIwE,EAAK,6EAYT,SAASC,EAAOC,GACf,IAAIzD,EAAQ,CACXyC,QAAagB,EAAO,GAAQrD,SAAUqD,EAAO,GAAK,SAAO,EACzDjB,MAASiB,EAAO,GAChBvE,MAASuE,EAAO,GAChBjD,UAAaiD,EAAO,GACpBvD,UAAauD,EAAO,IAKrB,MAHoB,MAAfA,EAAO,SAA8B,IAAfA,EAAO,KACjCzD,EAAMQ,UAAY,KAEZR,CACR,CAeA,SAAS0D,EAAgBzE,GACxB,IAAI0E,EACAhB,EACAc,EACAG,EAKJ,IAHAjB,EAAS,GACTiB,EAAO,EACPH,EAAQF,EAAGM,KAAM5E,GACTwE,IACPE,EAAU1E,EAAI6E,MAAOF,EAAML,EAAGQ,UAAYN,EAAO,GAAInE,SACxCA,QACZqD,EAAOqB,KAAML,GAEdhB,EAAOqB,KAAMR,EAAOC,IACpBG,EAAOL,EAAGQ,UACVN,EAAQF,EAAGM,KAAM5E,GAMlB,OAJA0E,EAAU1E,EAAI6E,MAAOF,IACRtE,QACZqD,EAAOqB,KAAML,GAEPhB,CACR,CClDA,SAAS7B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCUA,SAASsF,EAAQhF,GAChB,IAAI0D,EACAuB,EACApF,EAEJ,IAAMgC,EAAU7B,GACf,MAAM,IAAIgE,UAAWgB,EAAQ,kEAAmEhF,IAKjG,IAHA0D,EAASwB,EAAUlF,IACnBiF,EAAO,IAAI5B,MAAOc,UAAU9D,SACtB,GAAMqD,EACN7D,EAAI,EAAGA,EAAIoF,EAAK5E,OAAQR,IAC7BoF,EAAMpF,GAAMsE,UAAWtE,GAExB,OAAOsF,EAAYC,MAAO,KAAMH,EACjC,QCkEA,WACC,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EACAlE,EASJ,IANAwF,EAAUlB,UAAW,GACrBmB,EAASnB,UAAW,GAGpBoB,GADAG,EAAQvB,UAAW,GADnBsB,GAHAD,EAAQrB,UAAW,IAGL9D,UAECA,OACfuF,EAAMN,EACAzF,EAAI,EAAGA,EAAI4F,EAAO5F,IAAM,CAI7B,GAHAgG,EAAIL,EAAO3F,GACXkE,EAAII,UAAWtE,EAAE,GAEH,WADd8F,EAAOD,EAAO7F,EAAE0F,IAEVxB,EAAI,EACRA,EAAI,EACOA,GAAK8B,IAChB9B,EAAI8B,EAAI,QAEH,GAAc,SAATF,EACN5B,EAAI,GACRA,GAAK8B,GACI,GAEG,IADX9B,GAAK8B,KAEJ9B,GAAK8B,GAGI9B,GAAK8B,IAChB9B,GAAK8B,IACKA,IACT9B,GAAK8B,QAOP,GAHc,cAATF,GAAwB5B,EAAI,IAChCA,GAAK8B,GAED9B,EAAI,GAAKA,GAAK8B,EAClB,MAAM,IAAIE,WAAYf,EAAQ,+FAAgGnF,EAAGkE,KAGnI+B,EAAIT,EAASxF,IAGJ,GAAgB,IAAXyF,EACbM,GAAO7B,EAAI+B,EAEXF,GAAO7B,EAAI+B,CAEZ,CACD,OAAOF,CACR"} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..3188d51 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,r;e=this,r=function(){"use strict";function e(e){return"number"==typeof e}function r(e){var r,i="";for(r=0;r0&&(i-=1),a=n.toExponential(i)):a=n.toPrecision(r.precision),r.alternate||(a=l.call(a,b,"$1e"),a=l.call(a,w,"e"),a=l.call(a,h,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return a=l.call(a,f,"e+0$1"),a=l.call(a,g,"e-0$1"),r.alternate&&(a=l.call(a,u,"$1."),a=l.call(a,d,"$1.e")),n>=0&&r.sign&&(a=r.sign+a),a=r.specifier===p.call(r.specifier)?p.call(a):c.call(a)}function v(e){var r,i="";for(r=0;r127)throw new Error("invalid character code. Value: "+n.arg);n.arg=k(c)?String(n.arg):x(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":r||(n.precision=6),n.arg=m(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=y(n.arg,n.width,n.padRight)),p+=n.arg||"",l+=1}return p}var $=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function F(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function I(e){var r,i,a,n;for(i=[],n=0,a=$.exec(e);a;)(r=e.slice(n,$.lastIndex-a[0].length)).length&&i.push(r),i.push(F(a)),n=$.lastIndex,a=$.exec(e);return(r=e.slice(n)).length&&i.push(r),i}function T(e){return"string"==typeof e}function R(e){var r,i,a;if(!T(e))throw new TypeError(R("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=I(e),(i=new Array(arguments.length))[0]=r,a=1;a=c&&(l=c-1);else if("wrap"===s)l<0?(l+=c)<0&&0!=(l%=c)&&(l+=c):l>=c&&(l-=c)>=c&&(l%=c);else if("normalize"===s&&l<0&&(l+=c),l<0||l>=c)throw new RangeError(R("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",f,l));(p=e[f])<0&&0===r?o-=l*p:o+=l*p}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=r(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..c53e67e --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js","../node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js","../node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js","../node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/main.js","../node_modules/@stdlib/string-base-format-tokenize/lib/main.js","../node_modules/@stdlib/string-format/lib/is_string.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\nimport zeroPad from './zero_pad.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport formatInteger from './format_integer.js';\nimport isString from './is_string.js';\nimport formatDouble from './format_double.js';\nimport spacePad from './space_pad.js';\nimport zeroPad from './zero_pad.js';\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\nvar isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.\n\n\n// FUNCTIONS //\n\n/**\n* Initializes token object with properties of supplied format identifier object or default values if not present.\n*\n* @private\n* @param {Object} token - format identifier object\n* @returns {Object} token object\n*/\nfunction initialize( token ) {\n\tvar out = {};\n\tout.specifier = token.specifier;\n\tout.precision = ( token.precision === void 0 ) ? 1 : token.precision;\n\tout.width = token.width;\n\tout.flags = token.flags || '';\n\tout.mapping = token.mapping;\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Generates string from a token array by interpolating values.\n*\n* @param {Array} tokens - string parts and format identifier objects\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be an array\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var tokens = [ 'beep ', { 'specifier': 's' } ];\n* var out = formatInterpolate( tokens, 'boop' );\n* // returns 'beep boop'\n*/\nfunction formatInterpolate( tokens ) {\n\tvar hasPeriod;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isArray( tokens ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );\n\t}\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\thasPeriod = token.precision !== void 0;\n\t\t\ttoken = initialize( token );\n\t\t\tif ( !token.specifier ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );\n\t\t\t}\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasPeriod ) {\n\t\t\t\tif ( token.precision === '*' ) {\n\t\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t\t}\n\t\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\t\thasPeriod = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInterpolate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\tvar token = {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n\tif ( match[ 4 ] === '.' && match[ 5 ] === void 0 ) {\n\t\ttoken.precision = '1';\n\t}\n\treturn token;\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string into an array of string parts and format identifier objects.\n*\n* @param {string} str - input string\n* @returns {Array} tokens\n*\n* @example\n* var tokens = formatTokenize( 'Hello %s!' );\n* // returns [ 'Hello ', {...}, '!' ]\n*/\nfunction formatTokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nexport default formatTokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport interpolate from '@stdlib/string-base-format-interpolate';\nimport tokenize from '@stdlib/string-base-format-tokenize';\nimport isString from './is_string.js';\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default format;\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 format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["isNumber","value","zeros","n","i","out","zeroPad","str","width","right","negative","pad","length","startsWithMinus","substr","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","formatInteger","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","isString","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","spaces","spacePad","fromCharCode","isnan","isNaN","isArray","Array","initialize","flags","mapping","formatInterpolate","tokens","hasPeriod","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","RE","parse","match","formatTokenize","content","prev","exec","slice","lastIndex","push","format","args","tokenize","interpolate","apply","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","RangeError"],"mappings":";yCAsCA,SAASA,EAAUC,GAClB,MAA0B,iBAAVA,CACjB,CCAA,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASC,EAASC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,EACb,CAoCMM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,CAaT,CCpDA,IAAIQ,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAajC,SAASC,EAAeC,GACvB,IAAIC,EACAlB,EACAD,EAEJ,OAASkB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAlB,EAAMiB,EAAMG,IACZrB,EAAIsB,SAAUrB,EAAK,KACbsB,SAAUvB,GAAM,CACrB,IAAMJ,EAAUK,GACf,MAAM,IAAIuB,MAAO,2BAA6BvB,GAE/CD,EAAI,CACJ,CAkCD,OAjCKA,EAAI,IAA2B,MAApBkB,EAAME,WAA8B,KAATD,KAC1CnB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAIyB,SAAUN,GAClBD,EAAMQ,YACVzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAE5C1B,EAAM,IAAMA,IAEZA,EAAMD,EAAEyB,SAAUN,GACZnB,GAAMkB,EAAMQ,UAENR,EAAMQ,YACjBzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAF3C1B,EAAM,GAIFiB,EAAMU,OACV3B,EAAMiB,EAAMU,KAAO3B,IAGP,KAATkB,IACCD,EAAMW,YACV5B,EAAM,KAAOA,GAEdA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,IAEJ,IAATkB,GACCD,EAAMW,WAAiC,MAApB5B,EAAI8B,OAAQ,KACnC9B,EAAM,IAAMA,GAGPA,CACR,CC3EA,SAAS+B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCXA,IAAIoC,EAAMC,KAAKD,IACXtB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BmB,EAAUvB,OAAOC,UAAUsB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAazB,SAASC,EAAczB,GACtB,IAAI0B,EACA3C,EACA4C,EAAIC,WAAY5B,EAAMG,KAC1B,IAAME,SAAUsB,GAAM,CACrB,IAAMjD,EAAUsB,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2CvB,GAG7D4C,EAAI3B,EAAMG,GACV,CACD,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJnB,EAAM4C,EAAEE,cAAe7B,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJzB,EAAM4C,EAAEG,QAAS9B,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCO,EAAKY,GAAM,OACfD,EAAS1B,EAAMQ,WACD,IACbkB,GAAU,GAEX3C,EAAM4C,EAAEE,cAAeH,IAEvB3C,EAAM4C,EAAEI,YAAa/B,EAAMQ,WAEtBR,EAAMW,YACX5B,EAAMkC,EAAQL,KAAM7B,EAAKyC,EAAoB,OAC7CzC,EAAMkC,EAAQL,KAAM7B,EAAKwC,EAAoB,KAC7CxC,EAAMkC,EAAQL,KAAM7B,EAAKuC,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIhB,MAAO,mCAAqCN,EAAME,WAc7D,OAZAnB,EAAMkC,EAAQL,KAAM7B,EAAKmC,EAAmB,SAC5CnC,EAAMkC,EAAQL,KAAM7B,EAAKoC,EAAmB,SACvCnB,EAAMW,YACV5B,EAAMkC,EAAQL,KAAM7B,EAAKqC,EAAgB,OACzCrC,EAAMkC,EAAQL,KAAM7B,EAAKsC,EAAsB,SAE3CM,GAAK,GAAK3B,EAAMU,OACpB3B,EAAMiB,EAAMU,KAAO3B,GAEpBA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,EAElB,CC5EA,SAASiD,EAAQnD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASkD,EAAUhD,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAM+C,EAAQ3C,GACd2C,EAAQ3C,GAAQJ,CAElB,CC5BA,IAAIiD,EAAexC,OAAOwC,aACtBC,EAAQC,MACRC,EAAUC,MAAMD,QAYpB,SAASE,EAAYvC,GACpB,IAAIjB,EAAM,CAAA,EAMV,OALAA,EAAImB,UAAYF,EAAME,UACtBnB,EAAIyB,eAAkC,IAApBR,EAAMQ,UAAyB,EAAIR,EAAMQ,UAC3DzB,EAAIG,MAAQc,EAAMd,MAClBH,EAAIyD,MAAQxC,EAAMwC,OAAS,GAC3BzD,EAAI0D,QAAUzC,EAAMyC,QACb1D,CACR,CAmBA,SAAS2D,EAAmBC,GAC3B,IAAIC,EACAJ,EACAxC,EACA6C,EACAC,EACA/D,EACAgE,EACAjE,EACAkE,EAEJ,IAAMX,EAASM,GACd,MAAM,IAAIM,UAAW,8DAAgEN,EAAS,MAI/F,IAFA5D,EAAM,GACNgE,EAAM,EACAjE,EAAI,EAAGA,EAAI6D,EAAOrD,OAAQR,IAE/B,GAAKgC,EADLd,EAAQ2C,EAAQ7D,IAEfC,GAAOiB,MACD,CAGN,GAFA4C,OAAgC,IAApB5C,EAAMQ,YAClBR,EAAQuC,EAAYvC,IACRE,UACX,MAAM,IAAI+C,UAAW,oEAAqEnE,EAAG,cAAgBkB,EAAQ,MAMtH,IAJKA,EAAMyC,UACVM,EAAM/C,EAAMyC,SAEbD,EAAQxC,EAAMwC,MACRQ,EAAI,EAAGA,EAAIR,EAAMlD,OAAQ0D,IAE9B,OADAH,EAAOL,EAAM3B,OAAQmC,IAErB,IAAK,IACJhD,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAMkD,UAAW,EACjB,MACD,IAAK,IACJlD,EAAMkD,SAAWV,EAAMW,QAAS,KAAQ,EACxC,MACD,IAAK,IACJnD,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBuC,GAGtC,GAAqB,MAAhB7C,EAAMd,MAAgB,CAG1B,GAFAc,EAAMd,MAAQkB,SAAUgD,UAAWL,GAAO,IAC1CA,GAAO,EACFZ,EAAOnC,EAAMd,OACjB,MAAM,IAAI+D,UAAW,wCAA0CF,EAAM,6BAA+B/C,EAAMd,MAAQ,MAE9Gc,EAAMd,MAAQ,IAClBc,EAAMS,UAAW,EACjBT,EAAMd,OAASc,EAAMd,MAEtB,CACD,GAAK0D,GACqB,MAApB5C,EAAMQ,UAAoB,CAG9B,GAFAR,EAAMQ,UAAYJ,SAAUgD,UAAWL,GAAO,IAC9CA,GAAO,EACFZ,EAAOnC,EAAMQ,WACjB,MAAM,IAAIyC,UAAW,4CAA8CF,EAAM,6BAA+B/C,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBoC,GAAY,EAEb,CAGF,OADA5C,EAAMG,IAAMiD,UAAWL,GACd/C,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEC0C,IACJ5C,EAAMkD,UAAW,GAElBlD,EAAMG,IAAMJ,EAAeC,GAC3B,MACD,IAAK,IAEJA,EAAMqD,SAAW,EAAgBrD,EAAMQ,WAAa,EACpD,MACD,IAAK,IAEJ,IAAM2B,EAAOnC,EAAMG,KAAQ,CAE1B,IADA2C,EAAM1C,SAAUJ,EAAMG,IAAK,KAChB,GAAK2C,EAAM,IACrB,MAAM,IAAIxC,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgC,EAAOW,GACpBpD,OAAQM,EAAMG,KACd+B,EAAcY,EACf,CACD,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEEF,IACL5C,EAAMQ,UAAY,GAEnBR,EAAMG,IAAMsB,EAAczB,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAMqD,UAAY,GAAKrD,EAAMG,IAAIb,OAASU,EAAMqD,WACpDrD,EAAMG,IAAMH,EAAMG,IAAImD,UAAW,EAAGtD,EAAMqD,WAEtCrD,EAAMkD,SACVlD,EAAMG,IAAMnB,EAASgB,EAAMG,IAAKH,EAAMd,OAASc,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMd,QACjBc,EAAMG,IAAM8B,EAAUjC,EAAMG,IAAKH,EAAMd,MAAOc,EAAMS,WAErD1B,GAAOiB,EAAMG,KAAO,GACpB4C,GAAO,CACP,CAEF,OAAOhE,CACR,CC3LA,IAAIwE,EAAK,6EAYT,SAASC,EAAOC,GACf,IAAIzD,EAAQ,CACXyC,QAAagB,EAAO,GAAQrD,SAAUqD,EAAO,GAAK,SAAO,EACzDjB,MAASiB,EAAO,GAChBvE,MAASuE,EAAO,GAChBjD,UAAaiD,EAAO,GACpBvD,UAAauD,EAAO,IAKrB,MAHoB,MAAfA,EAAO,SAA8B,IAAfA,EAAO,KACjCzD,EAAMQ,UAAY,KAEZR,CACR,CAeA,SAAS0D,EAAgBzE,GACxB,IAAI0E,EACAhB,EACAc,EACAG,EAKJ,IAHAjB,EAAS,GACTiB,EAAO,EACPH,EAAQF,EAAGM,KAAM5E,GACTwE,IACPE,EAAU1E,EAAI6E,MAAOF,EAAML,EAAGQ,UAAYN,EAAO,GAAInE,SACxCA,QACZqD,EAAOqB,KAAML,GAEdhB,EAAOqB,KAAMR,EAAOC,IACpBG,EAAOL,EAAGQ,UACVN,EAAQF,EAAGM,KAAM5E,GAMlB,OAJA0E,EAAU1E,EAAI6E,MAAOF,IACRtE,QACZqD,EAAOqB,KAAML,GAEPhB,CACR,CClDA,SAAS7B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCUA,SAASsF,EAAQhF,GAChB,IAAI0D,EACAuB,EACApF,EAEJ,IAAMgC,EAAU7B,GACf,MAAM,IAAIgE,UAAWgB,EAAQ,kEAAmEhF,IAKjG,IAHA0D,EAASwB,EAAUlF,IACnBiF,EAAO,IAAI5B,MAAOc,UAAU9D,SACtB,GAAMqD,EACN7D,EAAI,EAAGA,EAAIoF,EAAK5E,OAAQR,IAC7BoF,EAAMpF,GAAMsE,UAAWtE,GAExB,OAAOsF,EAAYC,MAAO,KAAMH,EACjC,QCkEA,WACC,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EACAlE,EASJ,IANAwF,EAAUlB,UAAW,GACrBmB,EAASnB,UAAW,GAGpBoB,GADAG,EAAQvB,UAAW,GADnBsB,GAHAD,EAAQrB,UAAW,IAGL9D,UAECA,OACfuF,EAAMN,EACAzF,EAAI,EAAGA,EAAI4F,EAAO5F,IAAM,CAI7B,GAHAgG,EAAIL,EAAO3F,GACXkE,EAAII,UAAWtE,EAAE,GAEH,WADd8F,EAAOD,EAAO7F,EAAE0F,IAEVxB,EAAI,EACRA,EAAI,EACOA,GAAK8B,IAChB9B,EAAI8B,EAAI,QAEH,GAAc,SAATF,EACN5B,EAAI,GACRA,GAAK8B,GACI,GAEG,IADX9B,GAAK8B,KAEJ9B,GAAK8B,GAGI9B,GAAK8B,IAChB9B,GAAK8B,IACKA,IACT9B,GAAK8B,QAOP,GAHc,cAATF,GAAwB5B,EAAI,IAChCA,GAAK8B,GAED9B,EAAI,GAAKA,GAAK8B,EAClB,MAAM,IAAIE,WAAYf,EAAQ,+FAAgGnF,EAAGkE,KAGnI+B,EAAIT,EAASxF,IAGJ,GAAgB,IAAXyF,EACbM,GAAO7B,EAAI+B,EAEXF,GAAO7B,EAAI+B,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 2e347d0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/string-format' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index e84a375..b6a9bb6 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "version": "0.1.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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0", - "@stdlib/utils-library-manifest": "^0.1.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..5083d7b --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..9e2f956 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 7458ca91b97105ba49d6febfcf2cd8bbd8248fe8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 05:06:46 +0000 Subject: [PATCH 084/140] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47476a1..9c8c978 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1", "@stdlib/utils-library-manifest": "^0.2.0" }, From 6c8353a1498c9d94a805f22bd5850f1aa8cd067a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 07:29:57 +0000 Subject: [PATCH 085/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 6177 -------------------------------------------- stats_node.html | 6177 -------------------------------------------- 6 files changed, 12362 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ade6523..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,r;e=this,r=function(){"use strict";function e(e){return"number"==typeof e}function r(e){var r,i="";for(r=0;r0&&(i-=1),a=n.toExponential(i)):a=n.toPrecision(r.precision),r.alternate||(a=l.call(a,b,"$1e"),a=l.call(a,w,"e"),a=l.call(a,h,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return a=l.call(a,f,"e+0$1"),a=l.call(a,g,"e-0$1"),r.alternate&&(a=l.call(a,u,"$1."),a=l.call(a,d,"$1.e")),n>=0&&r.sign&&(a=r.sign+a),a=r.specifier===p.call(r.specifier)?p.call(a):c.call(a)}function v(e){var r,i="";for(r=0;r127)throw new Error("invalid character code. Value: "+n.arg);n.arg=k(c)?String(n.arg):x(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":r||(n.precision=6),n.arg=m(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=y(n.arg,n.width,n.padRight)),p+=n.arg||"",l+=1}return p}var $=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function F(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function I(e){var r,i,a,n;for(i=[],n=0,a=$.exec(e);a;)(r=e.slice(n,$.lastIndex-a[0].length)).length&&i.push(r),i.push(F(a)),n=$.lastIndex,a=$.exec(e);return(r=e.slice(n)).length&&i.push(r),i}function T(e){return"string"==typeof e}function R(e){var r,i,a;if(!T(e))throw new TypeError(R("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=I(e),(i=new Array(arguments.length))[0]=r,a=1;a=c&&(l=c-1);else if("wrap"===s)l<0?(l+=c)<0&&0!=(l%=c)&&(l+=c):l>=c&&(l-=c)>=c&&(l%=c);else if("normalize"===s&&l<0&&(l+=c),l<0||l>=c)throw new RangeError(R("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",f,l));(p=e[f])<0&&0===r?o-=l*p:o+=l*p}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=r(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index 241296b..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js","../node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js","../node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js","../node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/main.js","../node_modules/@stdlib/string-base-format-tokenize/lib/main.js","../node_modules/@stdlib/string-format/lib/is_string.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\nimport zeroPad from './zero_pad.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport formatInteger from './format_integer.js';\nimport isString from './is_string.js';\nimport formatDouble from './format_double.js';\nimport spacePad from './space_pad.js';\nimport zeroPad from './zero_pad.js';\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\nvar isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.\n\n\n// FUNCTIONS //\n\n/**\n* Initializes token object with properties of supplied format identifier object or default values if not present.\n*\n* @private\n* @param {Object} token - format identifier object\n* @returns {Object} token object\n*/\nfunction initialize( token ) {\n\tvar out = {};\n\tout.specifier = token.specifier;\n\tout.precision = ( token.precision === void 0 ) ? 1 : token.precision;\n\tout.width = token.width;\n\tout.flags = token.flags || '';\n\tout.mapping = token.mapping;\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Generates string from a token array by interpolating values.\n*\n* @param {Array} tokens - string parts and format identifier objects\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be an array\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var tokens = [ 'beep ', { 'specifier': 's' } ];\n* var out = formatInterpolate( tokens, 'boop' );\n* // returns 'beep boop'\n*/\nfunction formatInterpolate( tokens ) {\n\tvar hasPeriod;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isArray( tokens ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );\n\t}\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\thasPeriod = token.precision !== void 0;\n\t\t\ttoken = initialize( token );\n\t\t\tif ( !token.specifier ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );\n\t\t\t}\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasPeriod ) {\n\t\t\t\tif ( token.precision === '*' ) {\n\t\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t\t}\n\t\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\t\thasPeriod = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInterpolate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\tvar token = {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n\tif ( match[ 4 ] === '.' && match[ 5 ] === void 0 ) {\n\t\ttoken.precision = '1';\n\t}\n\treturn token;\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string into an array of string parts and format identifier objects.\n*\n* @param {string} str - input string\n* @returns {Array} tokens\n*\n* @example\n* var tokens = formatTokenize( 'Hello %s!' );\n* // returns [ 'Hello ', {...}, '!' ]\n*/\nfunction formatTokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nexport default formatTokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport interpolate from '@stdlib/string-base-format-interpolate';\nimport tokenize from '@stdlib/string-base-format-tokenize';\nimport isString from './is_string.js';\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default format;\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 format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["isNumber","value","zeros","n","i","out","zeroPad","str","width","right","negative","pad","length","startsWithMinus","substr","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","formatInteger","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","isString","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","spaces","spacePad","fromCharCode","isnan","isNaN","isArray","Array","initialize","flags","mapping","formatInterpolate","tokens","hasPeriod","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","RE","parse","match","formatTokenize","content","prev","exec","slice","lastIndex","push","format","args","tokenize","interpolate","apply","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","RangeError"],"mappings":";yCAsCA,SAASA,EAAUC,GAClB,MAA0B,iBAAVA,CACjB,CCAA,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASC,EAASC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,EACb,CAoCMM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,CAaT,CCpDA,IAAIQ,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAajC,SAASC,EAAeC,GACvB,IAAIC,EACAlB,EACAD,EAEJ,OAASkB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAlB,EAAMiB,EAAMG,IACZrB,EAAIsB,SAAUrB,EAAK,KACbsB,SAAUvB,GAAM,CACrB,IAAMJ,EAAUK,GACf,MAAM,IAAIuB,MAAO,2BAA6BvB,GAE/CD,EAAI,CACJ,CAkCD,OAjCKA,EAAI,IAA2B,MAApBkB,EAAME,WAA8B,KAATD,KAC1CnB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAIyB,SAAUN,GAClBD,EAAMQ,YACVzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAE5C1B,EAAM,IAAMA,IAEZA,EAAMD,EAAEyB,SAAUN,GACZnB,GAAMkB,EAAMQ,UAENR,EAAMQ,YACjBzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAF3C1B,EAAM,GAIFiB,EAAMU,OACV3B,EAAMiB,EAAMU,KAAO3B,IAGP,KAATkB,IACCD,EAAMW,YACV5B,EAAM,KAAOA,GAEdA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,IAEJ,IAATkB,GACCD,EAAMW,WAAiC,MAApB5B,EAAI8B,OAAQ,KACnC9B,EAAM,IAAMA,GAGPA,CACR,CC3EA,SAAS+B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCXA,IAAIoC,EAAMC,KAAKD,IACXtB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BmB,EAAUvB,OAAOC,UAAUsB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAazB,SAASC,EAAczB,GACtB,IAAI0B,EACA3C,EACA4C,EAAIC,WAAY5B,EAAMG,KAC1B,IAAME,SAAUsB,GAAM,CACrB,IAAMjD,EAAUsB,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2CvB,GAG7D4C,EAAI3B,EAAMG,GACV,CACD,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJnB,EAAM4C,EAAEE,cAAe7B,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJzB,EAAM4C,EAAEG,QAAS9B,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCO,EAAKY,GAAM,OACfD,EAAS1B,EAAMQ,WACD,IACbkB,GAAU,GAEX3C,EAAM4C,EAAEE,cAAeH,IAEvB3C,EAAM4C,EAAEI,YAAa/B,EAAMQ,WAEtBR,EAAMW,YACX5B,EAAMkC,EAAQL,KAAM7B,EAAKyC,EAAoB,OAC7CzC,EAAMkC,EAAQL,KAAM7B,EAAKwC,EAAoB,KAC7CxC,EAAMkC,EAAQL,KAAM7B,EAAKuC,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIhB,MAAO,mCAAqCN,EAAME,WAc7D,OAZAnB,EAAMkC,EAAQL,KAAM7B,EAAKmC,EAAmB,SAC5CnC,EAAMkC,EAAQL,KAAM7B,EAAKoC,EAAmB,SACvCnB,EAAMW,YACV5B,EAAMkC,EAAQL,KAAM7B,EAAKqC,EAAgB,OACzCrC,EAAMkC,EAAQL,KAAM7B,EAAKsC,EAAsB,SAE3CM,GAAK,GAAK3B,EAAMU,OACpB3B,EAAMiB,EAAMU,KAAO3B,GAEpBA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,EAElB,CC5EA,SAASiD,EAAQnD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASkD,EAAUhD,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAM+C,EAAQ3C,GACd2C,EAAQ3C,GAAQJ,CAElB,CC5BA,IAAIiD,EAAexC,OAAOwC,aACtBC,EAAQC,MACRC,EAAUC,MAAMD,QAYpB,SAASE,EAAYvC,GACpB,IAAIjB,EAAM,CAAA,EAMV,OALAA,EAAImB,UAAYF,EAAME,UACtBnB,EAAIyB,eAAkC,IAApBR,EAAMQ,UAAyB,EAAIR,EAAMQ,UAC3DzB,EAAIG,MAAQc,EAAMd,MAClBH,EAAIyD,MAAQxC,EAAMwC,OAAS,GAC3BzD,EAAI0D,QAAUzC,EAAMyC,QACb1D,CACR,CAmBA,SAAS2D,EAAmBC,GAC3B,IAAIC,EACAJ,EACAxC,EACA6C,EACAC,EACA/D,EACAgE,EACAjE,EACAkE,EAEJ,IAAMX,EAASM,GACd,MAAM,IAAIM,UAAW,8DAAgEN,EAAS,MAI/F,IAFA5D,EAAM,GACNgE,EAAM,EACAjE,EAAI,EAAGA,EAAI6D,EAAOrD,OAAQR,IAE/B,GAAKgC,EADLd,EAAQ2C,EAAQ7D,IAEfC,GAAOiB,MACD,CAGN,GAFA4C,OAAgC,IAApB5C,EAAMQ,YAClBR,EAAQuC,EAAYvC,IACRE,UACX,MAAM,IAAI+C,UAAW,oEAAqEnE,EAAG,cAAgBkB,EAAQ,MAMtH,IAJKA,EAAMyC,UACVM,EAAM/C,EAAMyC,SAEbD,EAAQxC,EAAMwC,MACRQ,EAAI,EAAGA,EAAIR,EAAMlD,OAAQ0D,IAE9B,OADAH,EAAOL,EAAM3B,OAAQmC,IAErB,IAAK,IACJhD,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAMkD,UAAW,EACjB,MACD,IAAK,IACJlD,EAAMkD,SAAWV,EAAMW,QAAS,KAAQ,EACxC,MACD,IAAK,IACJnD,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBuC,GAGtC,GAAqB,MAAhB7C,EAAMd,MAAgB,CAG1B,GAFAc,EAAMd,MAAQkB,SAAUgD,UAAWL,GAAO,IAC1CA,GAAO,EACFZ,EAAOnC,EAAMd,OACjB,MAAM,IAAI+D,UAAW,wCAA0CF,EAAM,6BAA+B/C,EAAMd,MAAQ,MAE9Gc,EAAMd,MAAQ,IAClBc,EAAMS,UAAW,EACjBT,EAAMd,OAASc,EAAMd,MAEtB,CACD,GAAK0D,GACqB,MAApB5C,EAAMQ,UAAoB,CAG9B,GAFAR,EAAMQ,UAAYJ,SAAUgD,UAAWL,GAAO,IAC9CA,GAAO,EACFZ,EAAOnC,EAAMQ,WACjB,MAAM,IAAIyC,UAAW,4CAA8CF,EAAM,6BAA+B/C,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBoC,GAAY,EAEb,CAGF,OADA5C,EAAMG,IAAMiD,UAAWL,GACd/C,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEC0C,IACJ5C,EAAMkD,UAAW,GAElBlD,EAAMG,IAAMJ,EAAeC,GAC3B,MACD,IAAK,IAEJA,EAAMqD,SAAW,EAAgBrD,EAAMQ,WAAa,EACpD,MACD,IAAK,IAEJ,IAAM2B,EAAOnC,EAAMG,KAAQ,CAE1B,IADA2C,EAAM1C,SAAUJ,EAAMG,IAAK,KAChB,GAAK2C,EAAM,IACrB,MAAM,IAAIxC,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgC,EAAOW,GACpBpD,OAAQM,EAAMG,KACd+B,EAAcY,EACf,CACD,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEEF,IACL5C,EAAMQ,UAAY,GAEnBR,EAAMG,IAAMsB,EAAczB,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAMqD,UAAY,GAAKrD,EAAMG,IAAIb,OAASU,EAAMqD,WACpDrD,EAAMG,IAAMH,EAAMG,IAAImD,UAAW,EAAGtD,EAAMqD,WAEtCrD,EAAMkD,SACVlD,EAAMG,IAAMnB,EAASgB,EAAMG,IAAKH,EAAMd,OAASc,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMd,QACjBc,EAAMG,IAAM8B,EAAUjC,EAAMG,IAAKH,EAAMd,MAAOc,EAAMS,WAErD1B,GAAOiB,EAAMG,KAAO,GACpB4C,GAAO,CACP,CAEF,OAAOhE,CACR,CC3LA,IAAIwE,EAAK,6EAYT,SAASC,EAAOC,GACf,IAAIzD,EAAQ,CACXyC,QAAagB,EAAO,GAAQrD,SAAUqD,EAAO,GAAK,SAAO,EACzDjB,MAASiB,EAAO,GAChBvE,MAASuE,EAAO,GAChBjD,UAAaiD,EAAO,GACpBvD,UAAauD,EAAO,IAKrB,MAHoB,MAAfA,EAAO,SAA8B,IAAfA,EAAO,KACjCzD,EAAMQ,UAAY,KAEZR,CACR,CAeA,SAAS0D,EAAgBzE,GACxB,IAAI0E,EACAhB,EACAc,EACAG,EAKJ,IAHAjB,EAAS,GACTiB,EAAO,EACPH,EAAQF,EAAGM,KAAM5E,GACTwE,IACPE,EAAU1E,EAAI6E,MAAOF,EAAML,EAAGQ,UAAYN,EAAO,GAAInE,SACxCA,QACZqD,EAAOqB,KAAML,GAEdhB,EAAOqB,KAAMR,EAAOC,IACpBG,EAAOL,EAAGQ,UACVN,EAAQF,EAAGM,KAAM5E,GAMlB,OAJA0E,EAAU1E,EAAI6E,MAAOF,IACRtE,QACZqD,EAAOqB,KAAML,GAEPhB,CACR,CClDA,SAAS7B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCUA,SAASsF,EAAQhF,GAChB,IAAI0D,EACAuB,EACApF,EAEJ,IAAMgC,EAAU7B,GACf,MAAM,IAAIgE,UAAWgB,EAAQ,kEAAmEhF,IAKjG,IAHA0D,EAASwB,EAAUlF,IACnBiF,EAAO,IAAI5B,MAAOc,UAAU9D,SACtB,GAAMqD,EACN7D,EAAI,EAAGA,EAAIoF,EAAK5E,OAAQR,IAC7BoF,EAAMpF,GAAMsE,UAAWtE,GAExB,OAAOsF,EAAYC,MAAO,KAAMH,EACjC,QCkEA,WACC,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EACAlE,EASJ,IANAwF,EAAUlB,UAAW,GACrBmB,EAASnB,UAAW,GAGpBoB,GADAG,EAAQvB,UAAW,GADnBsB,GAHAD,EAAQrB,UAAW,IAGL9D,UAECA,OACfuF,EAAMN,EACAzF,EAAI,EAAGA,EAAI4F,EAAO5F,IAAM,CAI7B,GAHAgG,EAAIL,EAAO3F,GACXkE,EAAII,UAAWtE,EAAE,GAEH,WADd8F,EAAOD,EAAO7F,EAAE0F,IAEVxB,EAAI,EACRA,EAAI,EACOA,GAAK8B,IAChB9B,EAAI8B,EAAI,QAEH,GAAc,SAATF,EACN5B,EAAI,GACRA,GAAK8B,GACI,GAEG,IADX9B,GAAK8B,KAEJ9B,GAAK8B,GAGI9B,GAAK8B,IAChB9B,GAAK8B,IACKA,IACT9B,GAAK8B,QAOP,GAHc,cAATF,GAAwB5B,EAAI,IAChCA,GAAK8B,GAED9B,EAAI,GAAKA,GAAK8B,EAClB,MAAM,IAAIE,WAAYf,EAAQ,+FAAgGnF,EAAGkE,KAGnI+B,EAAIT,EAASxF,IAGJ,GAAgB,IAAXyF,EACbM,GAAO7B,EAAI+B,EAEXF,GAAO7B,EAAI+B,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 3188d51..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,r;e=this,r=function(){"use strict";function e(e){return"number"==typeof e}function r(e){var r,i="";for(r=0;r0&&(i-=1),a=n.toExponential(i)):a=n.toPrecision(r.precision),r.alternate||(a=l.call(a,b,"$1e"),a=l.call(a,w,"e"),a=l.call(a,h,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return a=l.call(a,f,"e+0$1"),a=l.call(a,g,"e-0$1"),r.alternate&&(a=l.call(a,u,"$1."),a=l.call(a,d,"$1.e")),n>=0&&r.sign&&(a=r.sign+a),a=r.specifier===p.call(r.specifier)?p.call(a):c.call(a)}function v(e){var r,i="";for(r=0;r127)throw new Error("invalid character code. Value: "+n.arg);n.arg=k(c)?String(n.arg):x(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":r||(n.precision=6),n.arg=m(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=y(n.arg,n.width,n.padRight)),p+=n.arg||"",l+=1}return p}var $=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function F(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function I(e){var r,i,a,n;for(i=[],n=0,a=$.exec(e);a;)(r=e.slice(n,$.lastIndex-a[0].length)).length&&i.push(r),i.push(F(a)),n=$.lastIndex,a=$.exec(e);return(r=e.slice(n)).length&&i.push(r),i}function T(e){return"string"==typeof e}function R(e){var r,i,a;if(!T(e))throw new TypeError(R("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=I(e),(i=new Array(arguments.length))[0]=r,a=1;a=c&&(l=c-1);else if("wrap"===s)l<0?(l+=c)<0&&0!=(l%=c)&&(l+=c):l>=c&&(l-=c)>=c&&(l%=c);else if("normalize"===s&&l<0&&(l+=c),l<0||l>=c)throw new RangeError(R("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",f,l));(p=e[f])<0&&0===r?o-=l*p:o+=l*p}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=r(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index c53e67e..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js","../node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js","../node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js","../node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/main.js","../node_modules/@stdlib/string-base-format-tokenize/lib/main.js","../node_modules/@stdlib/string-format/lib/is_string.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\nimport zeroPad from './zero_pad.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport formatInteger from './format_integer.js';\nimport isString from './is_string.js';\nimport formatDouble from './format_double.js';\nimport spacePad from './space_pad.js';\nimport zeroPad from './zero_pad.js';\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\nvar isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.\n\n\n// FUNCTIONS //\n\n/**\n* Initializes token object with properties of supplied format identifier object or default values if not present.\n*\n* @private\n* @param {Object} token - format identifier object\n* @returns {Object} token object\n*/\nfunction initialize( token ) {\n\tvar out = {};\n\tout.specifier = token.specifier;\n\tout.precision = ( token.precision === void 0 ) ? 1 : token.precision;\n\tout.width = token.width;\n\tout.flags = token.flags || '';\n\tout.mapping = token.mapping;\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Generates string from a token array by interpolating values.\n*\n* @param {Array} tokens - string parts and format identifier objects\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be an array\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var tokens = [ 'beep ', { 'specifier': 's' } ];\n* var out = formatInterpolate( tokens, 'boop' );\n* // returns 'beep boop'\n*/\nfunction formatInterpolate( tokens ) {\n\tvar hasPeriod;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isArray( tokens ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );\n\t}\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\thasPeriod = token.precision !== void 0;\n\t\t\ttoken = initialize( token );\n\t\t\tif ( !token.specifier ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );\n\t\t\t}\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasPeriod ) {\n\t\t\t\tif ( token.precision === '*' ) {\n\t\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t\t}\n\t\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\t\thasPeriod = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInterpolate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\tvar token = {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n\tif ( match[ 4 ] === '.' && match[ 5 ] === void 0 ) {\n\t\ttoken.precision = '1';\n\t}\n\treturn token;\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string into an array of string parts and format identifier objects.\n*\n* @param {string} str - input string\n* @returns {Array} tokens\n*\n* @example\n* var tokens = formatTokenize( 'Hello %s!' );\n* // returns [ 'Hello ', {...}, '!' ]\n*/\nfunction formatTokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nexport default formatTokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport interpolate from '@stdlib/string-base-format-interpolate';\nimport tokenize from '@stdlib/string-base-format-tokenize';\nimport isString from './is_string.js';\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default format;\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 format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["isNumber","value","zeros","n","i","out","zeroPad","str","width","right","negative","pad","length","startsWithMinus","substr","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","formatInteger","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","isString","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","spaces","spacePad","fromCharCode","isnan","isNaN","isArray","Array","initialize","flags","mapping","formatInterpolate","tokens","hasPeriod","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","RE","parse","match","formatTokenize","content","prev","exec","slice","lastIndex","push","format","args","tokenize","interpolate","apply","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","RangeError"],"mappings":";yCAsCA,SAASA,EAAUC,GAClB,MAA0B,iBAAVA,CACjB,CCAA,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASC,EAASC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,EACb,CAoCMM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,CAaT,CCpDA,IAAIQ,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAajC,SAASC,EAAeC,GACvB,IAAIC,EACAlB,EACAD,EAEJ,OAASkB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAlB,EAAMiB,EAAMG,IACZrB,EAAIsB,SAAUrB,EAAK,KACbsB,SAAUvB,GAAM,CACrB,IAAMJ,EAAUK,GACf,MAAM,IAAIuB,MAAO,2BAA6BvB,GAE/CD,EAAI,CACJ,CAkCD,OAjCKA,EAAI,IAA2B,MAApBkB,EAAME,WAA8B,KAATD,KAC1CnB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAIyB,SAAUN,GAClBD,EAAMQ,YACVzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAE5C1B,EAAM,IAAMA,IAEZA,EAAMD,EAAEyB,SAAUN,GACZnB,GAAMkB,EAAMQ,UAENR,EAAMQ,YACjBzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAF3C1B,EAAM,GAIFiB,EAAMU,OACV3B,EAAMiB,EAAMU,KAAO3B,IAGP,KAATkB,IACCD,EAAMW,YACV5B,EAAM,KAAOA,GAEdA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,IAEJ,IAATkB,GACCD,EAAMW,WAAiC,MAApB5B,EAAI8B,OAAQ,KACnC9B,EAAM,IAAMA,GAGPA,CACR,CC3EA,SAAS+B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCXA,IAAIoC,EAAMC,KAAKD,IACXtB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BmB,EAAUvB,OAAOC,UAAUsB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAazB,SAASC,EAAczB,GACtB,IAAI0B,EACA3C,EACA4C,EAAIC,WAAY5B,EAAMG,KAC1B,IAAME,SAAUsB,GAAM,CACrB,IAAMjD,EAAUsB,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2CvB,GAG7D4C,EAAI3B,EAAMG,GACV,CACD,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJnB,EAAM4C,EAAEE,cAAe7B,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJzB,EAAM4C,EAAEG,QAAS9B,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCO,EAAKY,GAAM,OACfD,EAAS1B,EAAMQ,WACD,IACbkB,GAAU,GAEX3C,EAAM4C,EAAEE,cAAeH,IAEvB3C,EAAM4C,EAAEI,YAAa/B,EAAMQ,WAEtBR,EAAMW,YACX5B,EAAMkC,EAAQL,KAAM7B,EAAKyC,EAAoB,OAC7CzC,EAAMkC,EAAQL,KAAM7B,EAAKwC,EAAoB,KAC7CxC,EAAMkC,EAAQL,KAAM7B,EAAKuC,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIhB,MAAO,mCAAqCN,EAAME,WAc7D,OAZAnB,EAAMkC,EAAQL,KAAM7B,EAAKmC,EAAmB,SAC5CnC,EAAMkC,EAAQL,KAAM7B,EAAKoC,EAAmB,SACvCnB,EAAMW,YACV5B,EAAMkC,EAAQL,KAAM7B,EAAKqC,EAAgB,OACzCrC,EAAMkC,EAAQL,KAAM7B,EAAKsC,EAAsB,SAE3CM,GAAK,GAAK3B,EAAMU,OACpB3B,EAAMiB,EAAMU,KAAO3B,GAEpBA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,EAElB,CC5EA,SAASiD,EAAQnD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASkD,EAAUhD,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAM+C,EAAQ3C,GACd2C,EAAQ3C,GAAQJ,CAElB,CC5BA,IAAIiD,EAAexC,OAAOwC,aACtBC,EAAQC,MACRC,EAAUC,MAAMD,QAYpB,SAASE,EAAYvC,GACpB,IAAIjB,EAAM,CAAA,EAMV,OALAA,EAAImB,UAAYF,EAAME,UACtBnB,EAAIyB,eAAkC,IAApBR,EAAMQ,UAAyB,EAAIR,EAAMQ,UAC3DzB,EAAIG,MAAQc,EAAMd,MAClBH,EAAIyD,MAAQxC,EAAMwC,OAAS,GAC3BzD,EAAI0D,QAAUzC,EAAMyC,QACb1D,CACR,CAmBA,SAAS2D,EAAmBC,GAC3B,IAAIC,EACAJ,EACAxC,EACA6C,EACAC,EACA/D,EACAgE,EACAjE,EACAkE,EAEJ,IAAMX,EAASM,GACd,MAAM,IAAIM,UAAW,8DAAgEN,EAAS,MAI/F,IAFA5D,EAAM,GACNgE,EAAM,EACAjE,EAAI,EAAGA,EAAI6D,EAAOrD,OAAQR,IAE/B,GAAKgC,EADLd,EAAQ2C,EAAQ7D,IAEfC,GAAOiB,MACD,CAGN,GAFA4C,OAAgC,IAApB5C,EAAMQ,YAClBR,EAAQuC,EAAYvC,IACRE,UACX,MAAM,IAAI+C,UAAW,oEAAqEnE,EAAG,cAAgBkB,EAAQ,MAMtH,IAJKA,EAAMyC,UACVM,EAAM/C,EAAMyC,SAEbD,EAAQxC,EAAMwC,MACRQ,EAAI,EAAGA,EAAIR,EAAMlD,OAAQ0D,IAE9B,OADAH,EAAOL,EAAM3B,OAAQmC,IAErB,IAAK,IACJhD,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAMkD,UAAW,EACjB,MACD,IAAK,IACJlD,EAAMkD,SAAWV,EAAMW,QAAS,KAAQ,EACxC,MACD,IAAK,IACJnD,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBuC,GAGtC,GAAqB,MAAhB7C,EAAMd,MAAgB,CAG1B,GAFAc,EAAMd,MAAQkB,SAAUgD,UAAWL,GAAO,IAC1CA,GAAO,EACFZ,EAAOnC,EAAMd,OACjB,MAAM,IAAI+D,UAAW,wCAA0CF,EAAM,6BAA+B/C,EAAMd,MAAQ,MAE9Gc,EAAMd,MAAQ,IAClBc,EAAMS,UAAW,EACjBT,EAAMd,OAASc,EAAMd,MAEtB,CACD,GAAK0D,GACqB,MAApB5C,EAAMQ,UAAoB,CAG9B,GAFAR,EAAMQ,UAAYJ,SAAUgD,UAAWL,GAAO,IAC9CA,GAAO,EACFZ,EAAOnC,EAAMQ,WACjB,MAAM,IAAIyC,UAAW,4CAA8CF,EAAM,6BAA+B/C,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBoC,GAAY,EAEb,CAGF,OADA5C,EAAMG,IAAMiD,UAAWL,GACd/C,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEC0C,IACJ5C,EAAMkD,UAAW,GAElBlD,EAAMG,IAAMJ,EAAeC,GAC3B,MACD,IAAK,IAEJA,EAAMqD,SAAW,EAAgBrD,EAAMQ,WAAa,EACpD,MACD,IAAK,IAEJ,IAAM2B,EAAOnC,EAAMG,KAAQ,CAE1B,IADA2C,EAAM1C,SAAUJ,EAAMG,IAAK,KAChB,GAAK2C,EAAM,IACrB,MAAM,IAAIxC,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgC,EAAOW,GACpBpD,OAAQM,EAAMG,KACd+B,EAAcY,EACf,CACD,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEEF,IACL5C,EAAMQ,UAAY,GAEnBR,EAAMG,IAAMsB,EAAczB,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAMqD,UAAY,GAAKrD,EAAMG,IAAIb,OAASU,EAAMqD,WACpDrD,EAAMG,IAAMH,EAAMG,IAAImD,UAAW,EAAGtD,EAAMqD,WAEtCrD,EAAMkD,SACVlD,EAAMG,IAAMnB,EAASgB,EAAMG,IAAKH,EAAMd,OAASc,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMd,QACjBc,EAAMG,IAAM8B,EAAUjC,EAAMG,IAAKH,EAAMd,MAAOc,EAAMS,WAErD1B,GAAOiB,EAAMG,KAAO,GACpB4C,GAAO,CACP,CAEF,OAAOhE,CACR,CC3LA,IAAIwE,EAAK,6EAYT,SAASC,EAAOC,GACf,IAAIzD,EAAQ,CACXyC,QAAagB,EAAO,GAAQrD,SAAUqD,EAAO,GAAK,SAAO,EACzDjB,MAASiB,EAAO,GAChBvE,MAASuE,EAAO,GAChBjD,UAAaiD,EAAO,GACpBvD,UAAauD,EAAO,IAKrB,MAHoB,MAAfA,EAAO,SAA8B,IAAfA,EAAO,KACjCzD,EAAMQ,UAAY,KAEZR,CACR,CAeA,SAAS0D,EAAgBzE,GACxB,IAAI0E,EACAhB,EACAc,EACAG,EAKJ,IAHAjB,EAAS,GACTiB,EAAO,EACPH,EAAQF,EAAGM,KAAM5E,GACTwE,IACPE,EAAU1E,EAAI6E,MAAOF,EAAML,EAAGQ,UAAYN,EAAO,GAAInE,SACxCA,QACZqD,EAAOqB,KAAML,GAEdhB,EAAOqB,KAAMR,EAAOC,IACpBG,EAAOL,EAAGQ,UACVN,EAAQF,EAAGM,KAAM5E,GAMlB,OAJA0E,EAAU1E,EAAI6E,MAAOF,IACRtE,QACZqD,EAAOqB,KAAML,GAEPhB,CACR,CClDA,SAAS7B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCUA,SAASsF,EAAQhF,GAChB,IAAI0D,EACAuB,EACApF,EAEJ,IAAMgC,EAAU7B,GACf,MAAM,IAAIgE,UAAWgB,EAAQ,kEAAmEhF,IAKjG,IAHA0D,EAASwB,EAAUlF,IACnBiF,EAAO,IAAI5B,MAAOc,UAAU9D,SACtB,GAAMqD,EACN7D,EAAI,EAAGA,EAAIoF,EAAK5E,OAAQR,IAC7BoF,EAAMpF,GAAMsE,UAAWtE,GAExB,OAAOsF,EAAYC,MAAO,KAAMH,EACjC,QCkEA,WACC,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EACAlE,EASJ,IANAwF,EAAUlB,UAAW,GACrBmB,EAASnB,UAAW,GAGpBoB,GADAG,EAAQvB,UAAW,GADnBsB,GAHAD,EAAQrB,UAAW,IAGL9D,UAECA,OACfuF,EAAMN,EACAzF,EAAI,EAAGA,EAAI4F,EAAO5F,IAAM,CAI7B,GAHAgG,EAAIL,EAAO3F,GACXkE,EAAII,UAAWtE,EAAE,GAEH,WADd8F,EAAOD,EAAO7F,EAAE0F,IAEVxB,EAAI,EACRA,EAAI,EACOA,GAAK8B,IAChB9B,EAAI8B,EAAI,QAEH,GAAc,SAATF,EACN5B,EAAI,GACRA,GAAK8B,GACI,GAEG,IADX9B,GAAK8B,KAEJ9B,GAAK8B,GAGI9B,GAAK8B,IAChB9B,GAAK8B,IACKA,IACT9B,GAAK8B,QAOP,GAHc,cAATF,GAAwB5B,EAAI,IAChCA,GAAK8B,GAED9B,EAAI,GAAKA,GAAK8B,EAClB,MAAM,IAAIE,WAAYf,EAAQ,+FAAgGnF,EAAGkE,KAGnI+B,EAAIT,EAASxF,IAGJ,GAAgB,IAAXyF,EACbM,GAAO7B,EAAI+B,EAEXF,GAAO7B,EAAI+B,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 5083d7b..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 9e2f956..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5e4269b8ac718e06b270695d06e6e7d8406e3151 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 07:30:28 +0000 Subject: [PATCH 086/140] 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 | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 63 +- src/main.c | 110 - stats_browser.html | 6177 +++++++++++++++++++++ stats_node.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 53 files changed, 12402 insertions(+), 6138 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 2edd41a..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ade6523 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,r;e=this,r=function(){"use strict";function e(e){return"number"==typeof e}function r(e){var r,i="";for(r=0;r0&&(i-=1),a=n.toExponential(i)):a=n.toPrecision(r.precision),r.alternate||(a=l.call(a,b,"$1e"),a=l.call(a,w,"e"),a=l.call(a,h,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return a=l.call(a,f,"e+0$1"),a=l.call(a,g,"e-0$1"),r.alternate&&(a=l.call(a,u,"$1."),a=l.call(a,d,"$1.e")),n>=0&&r.sign&&(a=r.sign+a),a=r.specifier===p.call(r.specifier)?p.call(a):c.call(a)}function v(e){var r,i="";for(r=0;r127)throw new Error("invalid character code. Value: "+n.arg);n.arg=k(c)?String(n.arg):x(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":r||(n.precision=6),n.arg=m(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=y(n.arg,n.width,n.padRight)),p+=n.arg||"",l+=1}return p}var $=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function F(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function I(e){var r,i,a,n;for(i=[],n=0,a=$.exec(e);a;)(r=e.slice(n,$.lastIndex-a[0].length)).length&&i.push(r),i.push(F(a)),n=$.lastIndex,a=$.exec(e);return(r=e.slice(n)).length&&i.push(r),i}function T(e){return"string"==typeof e}function R(e){var r,i,a;if(!T(e))throw new TypeError(R("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=I(e),(i=new Array(arguments.length))[0]=r,a=1;a=c&&(l=c-1);else if("wrap"===s)l<0?(l+=c)<0&&0!=(l%=c)&&(l+=c):l>=c&&(l-=c)>=c&&(l%=c);else if("normalize"===s&&l<0&&(l+=c),l<0||l>=c)throw new RangeError(R("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",f,l));(p=e[f])<0&&0===r?o-=l*p:o+=l*p}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=r(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..241296b --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js","../node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js","../node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js","../node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/main.js","../node_modules/@stdlib/string-base-format-tokenize/lib/main.js","../node_modules/@stdlib/string-format/lib/is_string.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\nimport zeroPad from './zero_pad.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport formatInteger from './format_integer.js';\nimport isString from './is_string.js';\nimport formatDouble from './format_double.js';\nimport spacePad from './space_pad.js';\nimport zeroPad from './zero_pad.js';\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\nvar isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.\n\n\n// FUNCTIONS //\n\n/**\n* Initializes token object with properties of supplied format identifier object or default values if not present.\n*\n* @private\n* @param {Object} token - format identifier object\n* @returns {Object} token object\n*/\nfunction initialize( token ) {\n\tvar out = {};\n\tout.specifier = token.specifier;\n\tout.precision = ( token.precision === void 0 ) ? 1 : token.precision;\n\tout.width = token.width;\n\tout.flags = token.flags || '';\n\tout.mapping = token.mapping;\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Generates string from a token array by interpolating values.\n*\n* @param {Array} tokens - string parts and format identifier objects\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be an array\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var tokens = [ 'beep ', { 'specifier': 's' } ];\n* var out = formatInterpolate( tokens, 'boop' );\n* // returns 'beep boop'\n*/\nfunction formatInterpolate( tokens ) {\n\tvar hasPeriod;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isArray( tokens ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );\n\t}\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\thasPeriod = token.precision !== void 0;\n\t\t\ttoken = initialize( token );\n\t\t\tif ( !token.specifier ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );\n\t\t\t}\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasPeriod ) {\n\t\t\t\tif ( token.precision === '*' ) {\n\t\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t\t}\n\t\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\t\thasPeriod = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInterpolate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\tvar token = {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n\tif ( match[ 4 ] === '.' && match[ 5 ] === void 0 ) {\n\t\ttoken.precision = '1';\n\t}\n\treturn token;\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string into an array of string parts and format identifier objects.\n*\n* @param {string} str - input string\n* @returns {Array} tokens\n*\n* @example\n* var tokens = formatTokenize( 'Hello %s!' );\n* // returns [ 'Hello ', {...}, '!' ]\n*/\nfunction formatTokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nexport default formatTokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport interpolate from '@stdlib/string-base-format-interpolate';\nimport tokenize from '@stdlib/string-base-format-tokenize';\nimport isString from './is_string.js';\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default format;\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 format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["isNumber","value","zeros","n","i","out","zeroPad","str","width","right","negative","pad","length","startsWithMinus","substr","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","formatInteger","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","isString","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","spaces","spacePad","fromCharCode","isnan","isNaN","isArray","Array","initialize","flags","mapping","formatInterpolate","tokens","hasPeriod","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","RE","parse","match","formatTokenize","content","prev","exec","slice","lastIndex","push","format","args","tokenize","interpolate","apply","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","RangeError"],"mappings":";yCAsCA,SAASA,EAAUC,GAClB,MAA0B,iBAAVA,CACjB,CCAA,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASC,EAASC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,EACb,CAoCMM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,CAaT,CCpDA,IAAIQ,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAajC,SAASC,EAAeC,GACvB,IAAIC,EACAlB,EACAD,EAEJ,OAASkB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAlB,EAAMiB,EAAMG,IACZrB,EAAIsB,SAAUrB,EAAK,KACbsB,SAAUvB,GAAM,CACrB,IAAMJ,EAAUK,GACf,MAAM,IAAIuB,MAAO,2BAA6BvB,GAE/CD,EAAI,CACJ,CAkCD,OAjCKA,EAAI,IAA2B,MAApBkB,EAAME,WAA8B,KAATD,KAC1CnB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAIyB,SAAUN,GAClBD,EAAMQ,YACVzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAE5C1B,EAAM,IAAMA,IAEZA,EAAMD,EAAEyB,SAAUN,GACZnB,GAAMkB,EAAMQ,UAENR,EAAMQ,YACjBzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAF3C1B,EAAM,GAIFiB,EAAMU,OACV3B,EAAMiB,EAAMU,KAAO3B,IAGP,KAATkB,IACCD,EAAMW,YACV5B,EAAM,KAAOA,GAEdA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,IAEJ,IAATkB,GACCD,EAAMW,WAAiC,MAApB5B,EAAI8B,OAAQ,KACnC9B,EAAM,IAAMA,GAGPA,CACR,CC3EA,SAAS+B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCXA,IAAIoC,EAAMC,KAAKD,IACXtB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BmB,EAAUvB,OAAOC,UAAUsB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAazB,SAASC,EAAczB,GACtB,IAAI0B,EACA3C,EACA4C,EAAIC,WAAY5B,EAAMG,KAC1B,IAAME,SAAUsB,GAAM,CACrB,IAAMjD,EAAUsB,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2CvB,GAG7D4C,EAAI3B,EAAMG,GACV,CACD,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJnB,EAAM4C,EAAEE,cAAe7B,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJzB,EAAM4C,EAAEG,QAAS9B,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCO,EAAKY,GAAM,OACfD,EAAS1B,EAAMQ,WACD,IACbkB,GAAU,GAEX3C,EAAM4C,EAAEE,cAAeH,IAEvB3C,EAAM4C,EAAEI,YAAa/B,EAAMQ,WAEtBR,EAAMW,YACX5B,EAAMkC,EAAQL,KAAM7B,EAAKyC,EAAoB,OAC7CzC,EAAMkC,EAAQL,KAAM7B,EAAKwC,EAAoB,KAC7CxC,EAAMkC,EAAQL,KAAM7B,EAAKuC,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIhB,MAAO,mCAAqCN,EAAME,WAc7D,OAZAnB,EAAMkC,EAAQL,KAAM7B,EAAKmC,EAAmB,SAC5CnC,EAAMkC,EAAQL,KAAM7B,EAAKoC,EAAmB,SACvCnB,EAAMW,YACV5B,EAAMkC,EAAQL,KAAM7B,EAAKqC,EAAgB,OACzCrC,EAAMkC,EAAQL,KAAM7B,EAAKsC,EAAsB,SAE3CM,GAAK,GAAK3B,EAAMU,OACpB3B,EAAMiB,EAAMU,KAAO3B,GAEpBA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,EAElB,CC5EA,SAASiD,EAAQnD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASkD,EAAUhD,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAM+C,EAAQ3C,GACd2C,EAAQ3C,GAAQJ,CAElB,CC5BA,IAAIiD,EAAexC,OAAOwC,aACtBC,EAAQC,MACRC,EAAUC,MAAMD,QAYpB,SAASE,EAAYvC,GACpB,IAAIjB,EAAM,CAAA,EAMV,OALAA,EAAImB,UAAYF,EAAME,UACtBnB,EAAIyB,eAAkC,IAApBR,EAAMQ,UAAyB,EAAIR,EAAMQ,UAC3DzB,EAAIG,MAAQc,EAAMd,MAClBH,EAAIyD,MAAQxC,EAAMwC,OAAS,GAC3BzD,EAAI0D,QAAUzC,EAAMyC,QACb1D,CACR,CAmBA,SAAS2D,EAAmBC,GAC3B,IAAIC,EACAJ,EACAxC,EACA6C,EACAC,EACA/D,EACAgE,EACAjE,EACAkE,EAEJ,IAAMX,EAASM,GACd,MAAM,IAAIM,UAAW,8DAAgEN,EAAS,MAI/F,IAFA5D,EAAM,GACNgE,EAAM,EACAjE,EAAI,EAAGA,EAAI6D,EAAOrD,OAAQR,IAE/B,GAAKgC,EADLd,EAAQ2C,EAAQ7D,IAEfC,GAAOiB,MACD,CAGN,GAFA4C,OAAgC,IAApB5C,EAAMQ,YAClBR,EAAQuC,EAAYvC,IACRE,UACX,MAAM,IAAI+C,UAAW,oEAAqEnE,EAAG,cAAgBkB,EAAQ,MAMtH,IAJKA,EAAMyC,UACVM,EAAM/C,EAAMyC,SAEbD,EAAQxC,EAAMwC,MACRQ,EAAI,EAAGA,EAAIR,EAAMlD,OAAQ0D,IAE9B,OADAH,EAAOL,EAAM3B,OAAQmC,IAErB,IAAK,IACJhD,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAMkD,UAAW,EACjB,MACD,IAAK,IACJlD,EAAMkD,SAAWV,EAAMW,QAAS,KAAQ,EACxC,MACD,IAAK,IACJnD,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBuC,GAGtC,GAAqB,MAAhB7C,EAAMd,MAAgB,CAG1B,GAFAc,EAAMd,MAAQkB,SAAUgD,UAAWL,GAAO,IAC1CA,GAAO,EACFZ,EAAOnC,EAAMd,OACjB,MAAM,IAAI+D,UAAW,wCAA0CF,EAAM,6BAA+B/C,EAAMd,MAAQ,MAE9Gc,EAAMd,MAAQ,IAClBc,EAAMS,UAAW,EACjBT,EAAMd,OAASc,EAAMd,MAEtB,CACD,GAAK0D,GACqB,MAApB5C,EAAMQ,UAAoB,CAG9B,GAFAR,EAAMQ,UAAYJ,SAAUgD,UAAWL,GAAO,IAC9CA,GAAO,EACFZ,EAAOnC,EAAMQ,WACjB,MAAM,IAAIyC,UAAW,4CAA8CF,EAAM,6BAA+B/C,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBoC,GAAY,EAEb,CAGF,OADA5C,EAAMG,IAAMiD,UAAWL,GACd/C,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEC0C,IACJ5C,EAAMkD,UAAW,GAElBlD,EAAMG,IAAMJ,EAAeC,GAC3B,MACD,IAAK,IAEJA,EAAMqD,SAAW,EAAgBrD,EAAMQ,WAAa,EACpD,MACD,IAAK,IAEJ,IAAM2B,EAAOnC,EAAMG,KAAQ,CAE1B,IADA2C,EAAM1C,SAAUJ,EAAMG,IAAK,KAChB,GAAK2C,EAAM,IACrB,MAAM,IAAIxC,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgC,EAAOW,GACpBpD,OAAQM,EAAMG,KACd+B,EAAcY,EACf,CACD,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEEF,IACL5C,EAAMQ,UAAY,GAEnBR,EAAMG,IAAMsB,EAAczB,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAMqD,UAAY,GAAKrD,EAAMG,IAAIb,OAASU,EAAMqD,WACpDrD,EAAMG,IAAMH,EAAMG,IAAImD,UAAW,EAAGtD,EAAMqD,WAEtCrD,EAAMkD,SACVlD,EAAMG,IAAMnB,EAASgB,EAAMG,IAAKH,EAAMd,OAASc,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMd,QACjBc,EAAMG,IAAM8B,EAAUjC,EAAMG,IAAKH,EAAMd,MAAOc,EAAMS,WAErD1B,GAAOiB,EAAMG,KAAO,GACpB4C,GAAO,CACP,CAEF,OAAOhE,CACR,CC3LA,IAAIwE,EAAK,6EAYT,SAASC,EAAOC,GACf,IAAIzD,EAAQ,CACXyC,QAAagB,EAAO,GAAQrD,SAAUqD,EAAO,GAAK,SAAO,EACzDjB,MAASiB,EAAO,GAChBvE,MAASuE,EAAO,GAChBjD,UAAaiD,EAAO,GACpBvD,UAAauD,EAAO,IAKrB,MAHoB,MAAfA,EAAO,SAA8B,IAAfA,EAAO,KACjCzD,EAAMQ,UAAY,KAEZR,CACR,CAeA,SAAS0D,EAAgBzE,GACxB,IAAI0E,EACAhB,EACAc,EACAG,EAKJ,IAHAjB,EAAS,GACTiB,EAAO,EACPH,EAAQF,EAAGM,KAAM5E,GACTwE,IACPE,EAAU1E,EAAI6E,MAAOF,EAAML,EAAGQ,UAAYN,EAAO,GAAInE,SACxCA,QACZqD,EAAOqB,KAAML,GAEdhB,EAAOqB,KAAMR,EAAOC,IACpBG,EAAOL,EAAGQ,UACVN,EAAQF,EAAGM,KAAM5E,GAMlB,OAJA0E,EAAU1E,EAAI6E,MAAOF,IACRtE,QACZqD,EAAOqB,KAAML,GAEPhB,CACR,CClDA,SAAS7B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCUA,SAASsF,EAAQhF,GAChB,IAAI0D,EACAuB,EACApF,EAEJ,IAAMgC,EAAU7B,GACf,MAAM,IAAIgE,UAAWgB,EAAQ,kEAAmEhF,IAKjG,IAHA0D,EAASwB,EAAUlF,IACnBiF,EAAO,IAAI5B,MAAOc,UAAU9D,SACtB,GAAMqD,EACN7D,EAAI,EAAGA,EAAIoF,EAAK5E,OAAQR,IAC7BoF,EAAMpF,GAAMsE,UAAWtE,GAExB,OAAOsF,EAAYC,MAAO,KAAMH,EACjC,QCkEA,WACC,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EACAlE,EASJ,IANAwF,EAAUlB,UAAW,GACrBmB,EAASnB,UAAW,GAGpBoB,GADAG,EAAQvB,UAAW,GADnBsB,GAHAD,EAAQrB,UAAW,IAGL9D,UAECA,OACfuF,EAAMN,EACAzF,EAAI,EAAGA,EAAI4F,EAAO5F,IAAM,CAI7B,GAHAgG,EAAIL,EAAO3F,GACXkE,EAAII,UAAWtE,EAAE,GAEH,WADd8F,EAAOD,EAAO7F,EAAE0F,IAEVxB,EAAI,EACRA,EAAI,EACOA,GAAK8B,IAChB9B,EAAI8B,EAAI,QAEH,GAAc,SAATF,EACN5B,EAAI,GACRA,GAAK8B,GACI,GAEG,IADX9B,GAAK8B,KAEJ9B,GAAK8B,GAGI9B,GAAK8B,IAChB9B,GAAK8B,IACKA,IACT9B,GAAK8B,QAOP,GAHc,cAATF,GAAwB5B,EAAI,IAChCA,GAAK8B,GAED9B,EAAI,GAAKA,GAAK8B,EAClB,MAAM,IAAIE,WAAYf,EAAQ,+FAAgGnF,EAAGkE,KAGnI+B,EAAIT,EAASxF,IAGJ,GAAgB,IAAXyF,EACbM,GAAO7B,EAAI+B,EAEXF,GAAO7B,EAAI+B,CAEZ,CACD,OAAOF,CACR"} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..3188d51 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,r;e=this,r=function(){"use strict";function e(e){return"number"==typeof e}function r(e){var r,i="";for(r=0;r0&&(i-=1),a=n.toExponential(i)):a=n.toPrecision(r.precision),r.alternate||(a=l.call(a,b,"$1e"),a=l.call(a,w,"e"),a=l.call(a,h,""));break;default:throw new Error("invalid double notation. Value: "+r.specifier)}return a=l.call(a,f,"e+0$1"),a=l.call(a,g,"e-0$1"),r.alternate&&(a=l.call(a,u,"$1."),a=l.call(a,d,"$1.e")),n>=0&&r.sign&&(a=r.sign+a),a=r.specifier===p.call(r.specifier)?p.call(a):c.call(a)}function v(e){var r,i="";for(r=0;r127)throw new Error("invalid character code. Value: "+n.arg);n.arg=k(c)?String(n.arg):x(c)}break;case"e":case"E":case"f":case"F":case"g":case"G":r||(n.precision=6),n.arg=m(n);break;default:throw new Error("invalid specifier: "+n.specifier)}n.maxWidth>=0&&n.arg.length>n.maxWidth&&(n.arg=n.arg.substring(0,n.maxWidth)),n.padZeros?n.arg=i(n.arg,n.width||n.precision,n.padRight):n.width&&(n.arg=y(n.arg,n.width,n.padRight)),p+=n.arg||"",l+=1}return p}var $=/%(?:([1-9]\d*)\$)?([0 +\-#]*)(\*|\d+)?(?:(\.)(\*|\d+)?)?[hlL]?([%A-Za-z])/g;function F(e){var r={mapping:e[1]?parseInt(e[1],10):void 0,flags:e[2],width:e[3],precision:e[5],specifier:e[6]};return"."===e[4]&&void 0===e[5]&&(r.precision="1"),r}function I(e){var r,i,a,n;for(i=[],n=0,a=$.exec(e);a;)(r=e.slice(n,$.lastIndex-a[0].length)).length&&i.push(r),i.push(F(a)),n=$.lastIndex,a=$.exec(e);return(r=e.slice(n)).length&&i.push(r),i}function T(e){return"string"==typeof e}function R(e){var r,i,a;if(!T(e))throw new TypeError(R("invalid argument. First argument must be a string. Value: `%s`.",e));for(r=I(e),(i=new Array(arguments.length))[0]=r,a=1;a=c&&(l=c-1);else if("wrap"===s)l<0?(l+=c)<0&&0!=(l%=c)&&(l+=c):l>=c&&(l-=c)>=c&&(l%=c);else if("normalize"===s&&l<0&&(l+=c),l<0||l>=c)throw new RangeError(R("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",f,l));(p=e[f])<0&&0===r?o-=l*p:o+=l*p}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=r(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..c53e67e --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/string-base-format-interpolate/lib/is_number.js","../node_modules/@stdlib/string-base-format-interpolate/lib/zero_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_integer.js","../node_modules/@stdlib/string-base-format-interpolate/lib/is_string.js","../node_modules/@stdlib/string-base-format-interpolate/lib/format_double.js","../node_modules/@stdlib/string-base-format-interpolate/lib/space_pad.js","../node_modules/@stdlib/string-base-format-interpolate/lib/main.js","../node_modules/@stdlib/string-base-format-tokenize/lib/main.js","../node_modules/@stdlib/string-format/lib/is_string.js","../node_modules/@stdlib/string-format/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a number primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a number primitive\n*\n* @example\n* var bool = isNumber( 3.14 );\n* // returns true\n*\n* @example\n* var bool = isNumber( NaN );\n* // returns true\n*\n* @example\n* var bool = isNumber( new Number( 3.14 ) );\n* // returns false\n*/\nfunction isNumber( value ) {\n\treturn ( typeof value === 'number' ); // NOTE: we inline the `isNumber.isPrimitive` function from `@stdlib/assert/is-number` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isNumber;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Tests if a string starts with a minus sign (`-`).\n*\n* @private\n* @param {string} str - input string\n* @returns {boolean} boolean indicating if a string starts with a minus sign (`-`)\n*/\nfunction startsWithMinus( str ) {\n\treturn str[ 0 ] === '-';\n}\n\n/**\n* Returns a string of `n` zeros.\n*\n* @private\n* @param {number} n - number of zeros\n* @returns {string} string of zeros\n*/\nfunction zeros( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += '0';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with zeros to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction zeroPad( str, width, right ) {\n\tvar negative = false;\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tif ( startsWithMinus( str ) ) {\n\t\tnegative = true;\n\t\tstr = str.substr( 1 );\n\t}\n\tstr = ( right ) ?\n\t\tstr + zeros( pad ) :\n\t\tzeros( pad ) + str;\n\tif ( negative ) {\n\t\tstr = '-' + str;\n\t}\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default zeroPad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\nimport zeroPad from './zero_pad.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as an integer.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid integer\n* @returns {string} formatted token argument\n*/\nfunction formatInteger( token ) {\n\tvar base;\n\tvar out;\n\tvar i;\n\n\tswitch ( token.specifier ) {\n\tcase 'b':\n\t\t// Case: %b (binary)\n\t\tbase = 2;\n\t\tbreak;\n\tcase 'o':\n\t\t// Case: %o (octal)\n\t\tbase = 8;\n\t\tbreak;\n\tcase 'x':\n\tcase 'X':\n\t\t// Case: %x, %X (hexadecimal)\n\t\tbase = 16;\n\t\tbreak;\n\tcase 'd':\n\tcase 'i':\n\tcase 'u':\n\tdefault:\n\t\t// Case: %d, %i, %u (decimal)\n\t\tbase = 10;\n\t\tbreak;\n\t}\n\tout = token.arg;\n\ti = parseInt( out, 10 );\n\tif ( !isFinite( i ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( out ) ) {\n\t\t\tthrow new Error( 'invalid integer. Value: ' + out );\n\t\t}\n\t\ti = 0;\n\t}\n\tif ( i < 0 && ( token.specifier === 'u' || base !== 10 ) ) {\n\t\ti = 0xffffffff + i + 1;\n\t}\n\tif ( i < 0 ) {\n\t\tout = ( -i ).toString( base );\n\t\tif ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tout = '-' + out;\n\t} else {\n\t\tout = i.toString( base );\n\t\tif ( !i && !token.precision ) {\n\t\t\tout = '';\n\t\t} else if ( token.precision ) {\n\t\t\tout = zeroPad( out, token.precision, token.padRight );\n\t\t}\n\t\tif ( token.sign ) {\n\t\t\tout = token.sign + out;\n\t\t}\n\t}\n\tif ( base === 16 ) {\n\t\tif ( token.alternate ) {\n\t\t\tout = '0x' + out;\n\t\t}\n\t\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\t\tuppercase.call( out ) :\n\t\t\tlowercase.call( out );\n\t}\n\tif ( base === 8 ) {\n\t\tif ( token.alternate && out.charAt( 0 ) !== '0' ) {\n\t\t\tout = '0' + out;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInteger;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isNumber from './is_number.js';\n\n// NOTE: for the following, we explicitly avoid using stdlib packages in this particular package in order to avoid circular dependencies.\nvar abs = Math.abs; // eslint-disable-line stdlib/no-builtin-math\nvar lowercase = String.prototype.toLowerCase;\nvar uppercase = String.prototype.toUpperCase;\nvar replace = String.prototype.replace;\n\n\n// VARIABLES //\n\nvar RE_EXP_POS_DIGITS = /e\\+(\\d)$/;\nvar RE_EXP_NEG_DIGITS = /e-(\\d)$/;\nvar RE_ONLY_DIGITS = /^(\\d+)$/;\nvar RE_DIGITS_BEFORE_EXP = /^(\\d+)e/;\nvar RE_TRAILING_PERIOD_ZERO = /\\.0$/;\nvar RE_PERIOD_ZERO_EXP = /\\.0*e/;\nvar RE_ZERO_BEFORE_EXP = /(\\..*[^0])0*e/;\n\n\n// MAIN //\n\n/**\n* Formats a token object argument as a floating-point number.\n*\n* @private\n* @param {Object} token - token object\n* @throws {Error} must provide a valid floating-point number\n* @returns {string} formatted token argument\n*/\nfunction formatDouble( token ) {\n\tvar digits;\n\tvar out;\n\tvar f = parseFloat( token.arg );\n\tif ( !isFinite( f ) ) { // NOTE: We use the global `isFinite` function here instead of `@stdlib/math/base/assert/is-finite` in order to avoid circular dependencies.\n\t\tif ( !isNumber( token.arg ) ) {\n\t\t\tthrow new Error( 'invalid floating-point number. Value: ' + out );\n\t\t}\n\t\t// Case: NaN, Infinity, or -Infinity\n\t\tf = token.arg;\n\t}\n\tswitch ( token.specifier ) {\n\tcase 'e':\n\tcase 'E':\n\t\tout = f.toExponential( token.precision );\n\t\tbreak;\n\tcase 'f':\n\tcase 'F':\n\t\tout = f.toFixed( token.precision );\n\t\tbreak;\n\tcase 'g':\n\tcase 'G':\n\t\tif ( abs( f ) < 0.0001 ) {\n\t\t\tdigits = token.precision;\n\t\t\tif ( digits > 0 ) {\n\t\t\t\tdigits -= 1;\n\t\t\t}\n\t\t\tout = f.toExponential( digits );\n\t\t} else {\n\t\t\tout = f.toPrecision( token.precision );\n\t\t}\n\t\tif ( !token.alternate ) {\n\t\t\tout = replace.call( out, RE_ZERO_BEFORE_EXP, '$1e' );\n\t\t\tout = replace.call( out, RE_PERIOD_ZERO_EXP, 'e');\n\t\t\tout = replace.call( out, RE_TRAILING_PERIOD_ZERO, '' );\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tthrow new Error( 'invalid double notation. Value: ' + token.specifier );\n\t}\n\tout = replace.call( out, RE_EXP_POS_DIGITS, 'e+0$1' );\n\tout = replace.call( out, RE_EXP_NEG_DIGITS, 'e-0$1' );\n\tif ( token.alternate ) {\n\t\tout = replace.call( out, RE_ONLY_DIGITS, '$1.' );\n\t\tout = replace.call( out, RE_DIGITS_BEFORE_EXP, '$1.e' );\n\t}\n\tif ( f >= 0 && token.sign ) {\n\t\tout = token.sign + out;\n\t}\n\tout = ( token.specifier === uppercase.call( token.specifier ) ) ?\n\t\tuppercase.call( out ) :\n\t\tlowercase.call( out );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatDouble;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// FUNCTIONS //\n\n/**\n* Returns `n` spaces.\n*\n* @private\n* @param {number} n - number of spaces\n* @returns {string} string of spaces\n*/\nfunction spaces( n ) {\n\tvar out = '';\n\tvar i;\n\tfor ( i = 0; i < n; i++ ) {\n\t\tout += ' ';\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Pads a token with spaces to the specified width.\n*\n* @private\n* @param {string} str - token argument\n* @param {number} width - token width\n* @param {boolean} [right=false] - boolean indicating whether to pad to the right\n* @returns {string} padded token argument\n*/\nfunction spacePad( str, width, right ) {\n\tvar pad = width - str.length;\n\tif ( pad < 0 ) {\n\t\treturn str;\n\t}\n\tstr = ( right ) ?\n\t\tstr + spaces( pad ) :\n\t\tspaces( pad ) + str;\n\treturn str;\n}\n\n\n// EXPORTS //\n\nexport default spacePad;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport formatInteger from './format_integer.js';\nimport isString from './is_string.js';\nimport formatDouble from './format_double.js';\nimport spacePad from './space_pad.js';\nimport zeroPad from './zero_pad.js';\n\n\n// VARIABLES //\n\nvar fromCharCode = String.fromCharCode;\nvar isnan = isNaN; // NOTE: We use the global `isNaN` function here instead of `@stdlib/math/base/assert/is-nan` to avoid circular dependencies.\nvar isArray = Array.isArray; // NOTE: We use the global `Array.isArray` function here instead of `@stdlib/assert/is-array` to avoid circular dependencies.\n\n\n// FUNCTIONS //\n\n/**\n* Initializes token object with properties of supplied format identifier object or default values if not present.\n*\n* @private\n* @param {Object} token - format identifier object\n* @returns {Object} token object\n*/\nfunction initialize( token ) {\n\tvar out = {};\n\tout.specifier = token.specifier;\n\tout.precision = ( token.precision === void 0 ) ? 1 : token.precision;\n\tout.width = token.width;\n\tout.flags = token.flags || '';\n\tout.mapping = token.mapping;\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Generates string from a token array by interpolating values.\n*\n* @param {Array} tokens - string parts and format identifier objects\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be an array\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var tokens = [ 'beep ', { 'specifier': 's' } ];\n* var out = formatInterpolate( tokens, 'boop' );\n* // returns 'beep boop'\n*/\nfunction formatInterpolate( tokens ) {\n\tvar hasPeriod;\n\tvar flags;\n\tvar token;\n\tvar flag;\n\tvar num;\n\tvar out;\n\tvar pos;\n\tvar i;\n\tvar j;\n\n\tif ( !isArray( tokens ) ) {\n\t\tthrow new TypeError( 'invalid argument. First argument must be an array. Value: `' + tokens + '`.' );\n\t}\n\tout = '';\n\tpos = 1;\n\tfor ( i = 0; i < tokens.length; i++ ) {\n\t\ttoken = tokens[ i ];\n\t\tif ( isString( token ) ) {\n\t\t\tout += token;\n\t\t} else {\n\t\t\thasPeriod = token.precision !== void 0;\n\t\t\ttoken = initialize( token );\n\t\t\tif ( !token.specifier ) {\n\t\t\t\tthrow new TypeError( 'invalid argument. Token is missing `specifier` property. Index: `'+ i +'`. Value: `' + token + '`.' );\n\t\t\t}\n\t\t\tif ( token.mapping ) {\n\t\t\t\tpos = token.mapping;\n\t\t\t}\n\t\t\tflags = token.flags;\n\t\t\tfor ( j = 0; j < flags.length; j++ ) {\n\t\t\t\tflag = flags.charAt( j );\n\t\t\t\tswitch ( flag ) {\n\t\t\t\tcase ' ':\n\t\t\t\t\ttoken.sign = ' ';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '+':\n\t\t\t\t\ttoken.sign = '+';\n\t\t\t\t\tbreak;\n\t\t\t\tcase '-':\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase '0':\n\t\t\t\t\ttoken.padZeros = flags.indexOf( '-' ) < 0; // NOTE: We use built-in `Array.prototype.indexOf` here instead of `@stdlib/assert/contains` in order to avoid circular dependencies.\n\t\t\t\t\tbreak;\n\t\t\t\tcase '#':\n\t\t\t\t\ttoken.alternate = true;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error( 'invalid flag: ' + flag );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( token.width === '*' ) {\n\t\t\t\ttoken.width = parseInt( arguments[ pos ], 10 );\n\t\t\t\tpos += 1;\n\t\t\t\tif ( isnan( token.width ) ) {\n\t\t\t\t\tthrow new TypeError( 'the argument for * width at position ' + pos + ' is not a number. Value: `' + token.width + '`.' );\n\t\t\t\t}\n\t\t\t\tif ( token.width < 0 ) {\n\t\t\t\t\ttoken.padRight = true;\n\t\t\t\t\ttoken.width = -token.width;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( hasPeriod ) {\n\t\t\t\tif ( token.precision === '*' ) {\n\t\t\t\t\ttoken.precision = parseInt( arguments[ pos ], 10 );\n\t\t\t\t\tpos += 1;\n\t\t\t\t\tif ( isnan( token.precision ) ) {\n\t\t\t\t\t\tthrow new TypeError( 'the argument for * precision at position ' + pos + ' is not a number. Value: `' + token.precision + '`.' );\n\t\t\t\t\t}\n\t\t\t\t\tif ( token.precision < 0 ) {\n\t\t\t\t\t\ttoken.precision = 1;\n\t\t\t\t\t\thasPeriod = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoken.arg = arguments[ pos ];\n\t\t\tswitch ( token.specifier ) {\n\t\t\tcase 'b':\n\t\t\tcase 'o':\n\t\t\tcase 'x':\n\t\t\tcase 'X':\n\t\t\tcase 'd':\n\t\t\tcase 'i':\n\t\t\tcase 'u':\n\t\t\t\t// Case: %b (binary), %o (octal), %x, %X (hexadecimal), %d, %i (decimal), %u (unsigned decimal)\n\t\t\t\tif ( hasPeriod ) {\n\t\t\t\t\ttoken.padZeros = false;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatInteger( token );\n\t\t\t\tbreak;\n\t\t\tcase 's':\n\t\t\t\t// Case: %s (string)\n\t\t\t\ttoken.maxWidth = ( hasPeriod ) ? token.precision : -1;\n\t\t\t\tbreak;\n\t\t\tcase 'c':\n\t\t\t\t// Case: %c (character)\n\t\t\t\tif ( !isnan( token.arg ) ) {\n\t\t\t\t\tnum = parseInt( token.arg, 10 );\n\t\t\t\t\tif ( num < 0 || num > 127 ) {\n\t\t\t\t\t\tthrow new Error( 'invalid character code. Value: ' + token.arg );\n\t\t\t\t\t}\n\t\t\t\t\ttoken.arg = ( isnan( num ) ) ?\n\t\t\t\t\t\tString( token.arg ) :\n\t\t\t\t\t\tfromCharCode( num );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\tcase 'E':\n\t\t\tcase 'f':\n\t\t\tcase 'F':\n\t\t\tcase 'g':\n\t\t\tcase 'G':\n\t\t\t\t// Case: %e, %E (scientific notation), %f, %F (decimal floating point), %g, %G (uses the shorter of %e/E or %f/F)\n\t\t\t\tif ( !hasPeriod ) {\n\t\t\t\t\ttoken.precision = 6;\n\t\t\t\t}\n\t\t\t\ttoken.arg = formatDouble( token );\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error( 'invalid specifier: ' + token.specifier );\n\t\t\t}\n\t\t\t// Fit argument into field width...\n\t\t\tif ( token.maxWidth >= 0 && token.arg.length > token.maxWidth ) {\n\t\t\t\ttoken.arg = token.arg.substring( 0, token.maxWidth );\n\t\t\t}\n\t\t\tif ( token.padZeros ) {\n\t\t\t\ttoken.arg = zeroPad( token.arg, token.width || token.precision, token.padRight ); // eslint-disable-line max-len\n\t\t\t} else if ( token.width ) {\n\t\t\t\ttoken.arg = spacePad( token.arg, token.width, token.padRight );\n\t\t\t}\n\t\t\tout += token.arg || '';\n\t\t\tpos += 1;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nexport default formatInterpolate;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// VARIABLES //\n\nvar RE = /%(?:([1-9]\\d*)\\$)?([0 +\\-#]*)(\\*|\\d+)?(?:(\\.)(\\*|\\d+)?)?[hlL]?([%A-Za-z])/g;\n\n\n// FUNCTIONS //\n\n/**\n* Parses a delimiter.\n*\n* @private\n* @param {Array} match - regular expression match\n* @returns {Object} delimiter token object\n*/\nfunction parse( match ) {\n\tvar token = {\n\t\t'mapping': ( match[ 1 ] ) ? parseInt( match[ 1 ], 10 ) : void 0,\n\t\t'flags': match[ 2 ],\n\t\t'width': match[ 3 ],\n\t\t'precision': match[ 5 ],\n\t\t'specifier': match[ 6 ]\n\t};\n\tif ( match[ 4 ] === '.' && match[ 5 ] === void 0 ) {\n\t\ttoken.precision = '1';\n\t}\n\treturn token;\n}\n\n\n// MAIN //\n\n/**\n* Tokenizes a string into an array of string parts and format identifier objects.\n*\n* @param {string} str - input string\n* @returns {Array} tokens\n*\n* @example\n* var tokens = formatTokenize( 'Hello %s!' );\n* // returns [ 'Hello ', {...}, '!' ]\n*/\nfunction formatTokenize( str ) {\n\tvar content;\n\tvar tokens;\n\tvar match;\n\tvar prev;\n\n\ttokens = [];\n\tprev = 0;\n\tmatch = RE.exec( str );\n\twhile ( match ) {\n\t\tcontent = str.slice( prev, RE.lastIndex - match[ 0 ].length );\n\t\tif ( content.length ) {\n\t\t\ttokens.push( content );\n\t\t}\n\t\ttokens.push( parse( match ) );\n\t\tprev = RE.lastIndex;\n\t\tmatch = RE.exec( str );\n\t}\n\tcontent = str.slice( prev );\n\tif ( content.length ) {\n\t\ttokens.push( content );\n\t}\n\treturn tokens;\n}\n\n\n// EXPORTS //\n\nexport default formatTokenize;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Tests if a value is a string primitive.\n*\n* @param {*} value - value to test\n* @returns {boolean} boolean indicating if a value is a string primitive\n*\n* @example\n* var bool = isString( 'beep' );\n* // returns true\n*\n* @example\n* var bool = isString( new String( 'beep' ) );\n* // returns false\n*/\nfunction isString( value ) {\n\treturn ( typeof value === 'string' ); // NOTE: we inline the `isString.isPrimitive` function from `@stdlib/assert/is-string` in order to avoid circular dependencies.\n}\n\n\n// EXPORTS //\n\nexport default isString;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport interpolate from '@stdlib/string-base-format-interpolate';\nimport tokenize from '@stdlib/string-base-format-tokenize';\nimport isString from './is_string.js';\n\n\n// MAIN //\n\n/**\n* Inserts supplied variable values into a format string.\n*\n* @param {string} str - input string\n* @param {Array} ...args - variable values\n* @throws {TypeError} first argument must be a string\n* @throws {Error} invalid flags\n* @returns {string} formatted string\n*\n* @example\n* var str = format( 'Hello %s!', 'world' );\n* // returns 'Hello world!'\n*\n* @example\n* var str = format( 'Pi: ~%.2f', 3.141592653589793 );\n* // returns 'Pi: ~3.14'\n*/\nfunction format( str ) {\n\tvar tokens;\n\tvar args;\n\tvar i;\n\n\tif ( !isString( str ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );\n\t}\n\ttokens = tokenize( str );\n\targs = new Array( arguments.length );\n\targs[ 0 ] = tokens;\n\tfor ( i = 1; i < args.length; i++ ) {\n\t\targs[ i ] = arguments[ i ];\n\t}\n\treturn interpolate.apply( null, args );\n}\n\n\n// EXPORTS //\n\nexport default format;\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 format from '@stdlib/string-format';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["isNumber","value","zeros","n","i","out","zeroPad","str","width","right","negative","pad","length","startsWithMinus","substr","lowercase","String","prototype","toLowerCase","uppercase","toUpperCase","formatInteger","token","base","specifier","arg","parseInt","isFinite","Error","toString","precision","padRight","sign","alternate","call","charAt","isString","abs","Math","replace","RE_EXP_POS_DIGITS","RE_EXP_NEG_DIGITS","RE_ONLY_DIGITS","RE_DIGITS_BEFORE_EXP","RE_TRAILING_PERIOD_ZERO","RE_PERIOD_ZERO_EXP","RE_ZERO_BEFORE_EXP","formatDouble","digits","f","parseFloat","toExponential","toFixed","toPrecision","spaces","spacePad","fromCharCode","isnan","isNaN","isArray","Array","initialize","flags","mapping","formatInterpolate","tokens","hasPeriod","flag","num","pos","j","TypeError","padZeros","indexOf","arguments","maxWidth","substring","RE","parse","match","formatTokenize","content","prev","exec","slice","lastIndex","push","format","args","tokenize","interpolate","apply","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","RangeError"],"mappings":";yCAsCA,SAASA,EAAUC,GAClB,MAA0B,iBAAVA,CACjB,CCAA,SAASC,EAAOC,GACf,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASC,EAASC,EAAKC,EAAOC,GAC7B,IAAIC,GAAW,EACXC,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,IAnCZ,SAA0BJ,GACzB,MAAoB,MAAbA,EAAK,EACb,CAoCMM,CAAiBN,KACrBG,GAAW,EACXH,EAAMA,EAAIO,OAAQ,IAEnBP,EAAM,EACLA,EAAML,EAAOS,GACbT,EAAOS,GAAQJ,EACXG,IACJH,EAAM,IAAMA,IAVLA,CAaT,CCpDA,IAAIQ,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAajC,SAASC,EAAeC,GACvB,IAAIC,EACAlB,EACAD,EAEJ,OAASkB,EAAME,WACf,IAAK,IAEJD,EAAO,EACP,MACD,IAAK,IAEJA,EAAO,EACP,MACD,IAAK,IACL,IAAK,IAEJA,EAAO,GACP,MAID,QAECA,EAAO,GAKR,GAFAlB,EAAMiB,EAAMG,IACZrB,EAAIsB,SAAUrB,EAAK,KACbsB,SAAUvB,GAAM,CACrB,IAAMJ,EAAUK,GACf,MAAM,IAAIuB,MAAO,2BAA6BvB,GAE/CD,EAAI,CACJ,CAkCD,OAjCKA,EAAI,IAA2B,MAApBkB,EAAME,WAA8B,KAATD,KAC1CnB,EAAI,WAAaA,EAAI,GAEjBA,EAAI,GACRC,IAASD,GAAIyB,SAAUN,GAClBD,EAAMQ,YACVzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAE5C1B,EAAM,IAAMA,IAEZA,EAAMD,EAAEyB,SAAUN,GACZnB,GAAMkB,EAAMQ,UAENR,EAAMQ,YACjBzB,EAAMC,EAASD,EAAKiB,EAAMQ,UAAWR,EAAMS,WAF3C1B,EAAM,GAIFiB,EAAMU,OACV3B,EAAMiB,EAAMU,KAAO3B,IAGP,KAATkB,IACCD,EAAMW,YACV5B,EAAM,KAAOA,GAEdA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,IAEJ,IAATkB,GACCD,EAAMW,WAAiC,MAApB5B,EAAI8B,OAAQ,KACnC9B,EAAM,IAAMA,GAGPA,CACR,CC3EA,SAAS+B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCXA,IAAIoC,EAAMC,KAAKD,IACXtB,EAAYC,OAAOC,UAAUC,YAC7BC,EAAYH,OAAOC,UAAUG,YAC7BmB,EAAUvB,OAAOC,UAAUsB,QAK3BC,EAAoB,WACpBC,EAAoB,UACpBC,EAAiB,UACjBC,EAAuB,UACvBC,EAA0B,OAC1BC,EAAqB,QACrBC,EAAqB,gBAazB,SAASC,EAAczB,GACtB,IAAI0B,EACA3C,EACA4C,EAAIC,WAAY5B,EAAMG,KAC1B,IAAME,SAAUsB,GAAM,CACrB,IAAMjD,EAAUsB,EAAMG,KACrB,MAAM,IAAIG,MAAO,yCAA2CvB,GAG7D4C,EAAI3B,EAAMG,GACV,CACD,OAASH,EAAME,WACf,IAAK,IACL,IAAK,IACJnB,EAAM4C,EAAEE,cAAe7B,EAAMQ,WAC7B,MACD,IAAK,IACL,IAAK,IACJzB,EAAM4C,EAAEG,QAAS9B,EAAMQ,WACvB,MACD,IAAK,IACL,IAAK,IACCO,EAAKY,GAAM,OACfD,EAAS1B,EAAMQ,WACD,IACbkB,GAAU,GAEX3C,EAAM4C,EAAEE,cAAeH,IAEvB3C,EAAM4C,EAAEI,YAAa/B,EAAMQ,WAEtBR,EAAMW,YACX5B,EAAMkC,EAAQL,KAAM7B,EAAKyC,EAAoB,OAC7CzC,EAAMkC,EAAQL,KAAM7B,EAAKwC,EAAoB,KAC7CxC,EAAMkC,EAAQL,KAAM7B,EAAKuC,EAAyB,KAEnD,MACD,QACC,MAAM,IAAIhB,MAAO,mCAAqCN,EAAME,WAc7D,OAZAnB,EAAMkC,EAAQL,KAAM7B,EAAKmC,EAAmB,SAC5CnC,EAAMkC,EAAQL,KAAM7B,EAAKoC,EAAmB,SACvCnB,EAAMW,YACV5B,EAAMkC,EAAQL,KAAM7B,EAAKqC,EAAgB,OACzCrC,EAAMkC,EAAQL,KAAM7B,EAAKsC,EAAsB,SAE3CM,GAAK,GAAK3B,EAAMU,OACpB3B,EAAMiB,EAAMU,KAAO3B,GAEpBA,EAAQiB,EAAME,YAAcL,EAAUe,KAAMZ,EAAME,WACjDL,EAAUe,KAAM7B,GAChBU,EAAUmB,KAAM7B,EAElB,CC5EA,SAASiD,EAAQnD,GAChB,IACIC,EADAC,EAAM,GAEV,IAAMD,EAAI,EAAGA,EAAID,EAAGC,IACnBC,GAAO,IAER,OAAOA,CACR,CAcA,SAASkD,EAAUhD,EAAKC,EAAOC,GAC9B,IAAIE,EAAMH,EAAQD,EAAIK,OACtB,OAAKD,EAAM,EACHJ,EAERA,EAAM,EACLA,EAAM+C,EAAQ3C,GACd2C,EAAQ3C,GAAQJ,CAElB,CC5BA,IAAIiD,EAAexC,OAAOwC,aACtBC,EAAQC,MACRC,EAAUC,MAAMD,QAYpB,SAASE,EAAYvC,GACpB,IAAIjB,EAAM,CAAA,EAMV,OALAA,EAAImB,UAAYF,EAAME,UACtBnB,EAAIyB,eAAkC,IAApBR,EAAMQ,UAAyB,EAAIR,EAAMQ,UAC3DzB,EAAIG,MAAQc,EAAMd,MAClBH,EAAIyD,MAAQxC,EAAMwC,OAAS,GAC3BzD,EAAI0D,QAAUzC,EAAMyC,QACb1D,CACR,CAmBA,SAAS2D,EAAmBC,GAC3B,IAAIC,EACAJ,EACAxC,EACA6C,EACAC,EACA/D,EACAgE,EACAjE,EACAkE,EAEJ,IAAMX,EAASM,GACd,MAAM,IAAIM,UAAW,8DAAgEN,EAAS,MAI/F,IAFA5D,EAAM,GACNgE,EAAM,EACAjE,EAAI,EAAGA,EAAI6D,EAAOrD,OAAQR,IAE/B,GAAKgC,EADLd,EAAQ2C,EAAQ7D,IAEfC,GAAOiB,MACD,CAGN,GAFA4C,OAAgC,IAApB5C,EAAMQ,YAClBR,EAAQuC,EAAYvC,IACRE,UACX,MAAM,IAAI+C,UAAW,oEAAqEnE,EAAG,cAAgBkB,EAAQ,MAMtH,IAJKA,EAAMyC,UACVM,EAAM/C,EAAMyC,SAEbD,EAAQxC,EAAMwC,MACRQ,EAAI,EAAGA,EAAIR,EAAMlD,OAAQ0D,IAE9B,OADAH,EAAOL,EAAM3B,OAAQmC,IAErB,IAAK,IACJhD,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMU,KAAO,IACb,MACD,IAAK,IACJV,EAAMS,UAAW,EACjBT,EAAMkD,UAAW,EACjB,MACD,IAAK,IACJlD,EAAMkD,SAAWV,EAAMW,QAAS,KAAQ,EACxC,MACD,IAAK,IACJnD,EAAMW,WAAY,EAClB,MACD,QACC,MAAM,IAAIL,MAAO,iBAAmBuC,GAGtC,GAAqB,MAAhB7C,EAAMd,MAAgB,CAG1B,GAFAc,EAAMd,MAAQkB,SAAUgD,UAAWL,GAAO,IAC1CA,GAAO,EACFZ,EAAOnC,EAAMd,OACjB,MAAM,IAAI+D,UAAW,wCAA0CF,EAAM,6BAA+B/C,EAAMd,MAAQ,MAE9Gc,EAAMd,MAAQ,IAClBc,EAAMS,UAAW,EACjBT,EAAMd,OAASc,EAAMd,MAEtB,CACD,GAAK0D,GACqB,MAApB5C,EAAMQ,UAAoB,CAG9B,GAFAR,EAAMQ,UAAYJ,SAAUgD,UAAWL,GAAO,IAC9CA,GAAO,EACFZ,EAAOnC,EAAMQ,WACjB,MAAM,IAAIyC,UAAW,4CAA8CF,EAAM,6BAA+B/C,EAAMQ,UAAY,MAEtHR,EAAMQ,UAAY,IACtBR,EAAMQ,UAAY,EAClBoC,GAAY,EAEb,CAGF,OADA5C,EAAMG,IAAMiD,UAAWL,GACd/C,EAAME,WACf,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEC0C,IACJ5C,EAAMkD,UAAW,GAElBlD,EAAMG,IAAMJ,EAAeC,GAC3B,MACD,IAAK,IAEJA,EAAMqD,SAAW,EAAgBrD,EAAMQ,WAAa,EACpD,MACD,IAAK,IAEJ,IAAM2B,EAAOnC,EAAMG,KAAQ,CAE1B,IADA2C,EAAM1C,SAAUJ,EAAMG,IAAK,KAChB,GAAK2C,EAAM,IACrB,MAAM,IAAIxC,MAAO,kCAAoCN,EAAMG,KAE5DH,EAAMG,IAAQgC,EAAOW,GACpBpD,OAAQM,EAAMG,KACd+B,EAAcY,EACf,CACD,MACD,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IAEEF,IACL5C,EAAMQ,UAAY,GAEnBR,EAAMG,IAAMsB,EAAczB,GAC1B,MACD,QACC,MAAM,IAAIM,MAAO,sBAAwBN,EAAME,WAG3CF,EAAMqD,UAAY,GAAKrD,EAAMG,IAAIb,OAASU,EAAMqD,WACpDrD,EAAMG,IAAMH,EAAMG,IAAImD,UAAW,EAAGtD,EAAMqD,WAEtCrD,EAAMkD,SACVlD,EAAMG,IAAMnB,EAASgB,EAAMG,IAAKH,EAAMd,OAASc,EAAMQ,UAAWR,EAAMS,UAC3DT,EAAMd,QACjBc,EAAMG,IAAM8B,EAAUjC,EAAMG,IAAKH,EAAMd,MAAOc,EAAMS,WAErD1B,GAAOiB,EAAMG,KAAO,GACpB4C,GAAO,CACP,CAEF,OAAOhE,CACR,CC3LA,IAAIwE,EAAK,6EAYT,SAASC,EAAOC,GACf,IAAIzD,EAAQ,CACXyC,QAAagB,EAAO,GAAQrD,SAAUqD,EAAO,GAAK,SAAO,EACzDjB,MAASiB,EAAO,GAChBvE,MAASuE,EAAO,GAChBjD,UAAaiD,EAAO,GACpBvD,UAAauD,EAAO,IAKrB,MAHoB,MAAfA,EAAO,SAA8B,IAAfA,EAAO,KACjCzD,EAAMQ,UAAY,KAEZR,CACR,CAeA,SAAS0D,EAAgBzE,GACxB,IAAI0E,EACAhB,EACAc,EACAG,EAKJ,IAHAjB,EAAS,GACTiB,EAAO,EACPH,EAAQF,EAAGM,KAAM5E,GACTwE,IACPE,EAAU1E,EAAI6E,MAAOF,EAAML,EAAGQ,UAAYN,EAAO,GAAInE,SACxCA,QACZqD,EAAOqB,KAAML,GAEdhB,EAAOqB,KAAMR,EAAOC,IACpBG,EAAOL,EAAGQ,UACVN,EAAQF,EAAGM,KAAM5E,GAMlB,OAJA0E,EAAU1E,EAAI6E,MAAOF,IACRtE,QACZqD,EAAOqB,KAAML,GAEPhB,CACR,CClDA,SAAS7B,EAAUnC,GAClB,MAA0B,iBAAVA,CACjB,CCUA,SAASsF,EAAQhF,GAChB,IAAI0D,EACAuB,EACApF,EAEJ,IAAMgC,EAAU7B,GACf,MAAM,IAAIgE,UAAWgB,EAAQ,kEAAmEhF,IAKjG,IAHA0D,EAASwB,EAAUlF,IACnBiF,EAAO,IAAI5B,MAAOc,UAAU9D,SACtB,GAAMqD,EACN7D,EAAI,EAAGA,EAAIoF,EAAK5E,OAAQR,IAC7BoF,EAAMpF,GAAMsE,UAAWtE,GAExB,OAAOsF,EAAYC,MAAO,KAAMH,EACjC,QCkEA,WACC,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EACAlE,EASJ,IANAwF,EAAUlB,UAAW,GACrBmB,EAASnB,UAAW,GAGpBoB,GADAG,EAAQvB,UAAW,GADnBsB,GAHAD,EAAQrB,UAAW,IAGL9D,UAECA,OACfuF,EAAMN,EACAzF,EAAI,EAAGA,EAAI4F,EAAO5F,IAAM,CAI7B,GAHAgG,EAAIL,EAAO3F,GACXkE,EAAII,UAAWtE,EAAE,GAEH,WADd8F,EAAOD,EAAO7F,EAAE0F,IAEVxB,EAAI,EACRA,EAAI,EACOA,GAAK8B,IAChB9B,EAAI8B,EAAI,QAEH,GAAc,SAATF,EACN5B,EAAI,GACRA,GAAK8B,GACI,GAEG,IADX9B,GAAK8B,KAEJ9B,GAAK8B,GAGI9B,GAAK8B,IAChB9B,GAAK8B,IACKA,IACT9B,GAAK8B,QAOP,GAHc,cAATF,GAAwB5B,EAAI,IAChCA,GAAK8B,GAED9B,EAAI,GAAKA,GAAK8B,EAClB,MAAM,IAAIE,WAAYf,EAAQ,+FAAgGnF,EAAGkE,KAGnI+B,EAAIT,EAASxF,IAGJ,GAAgB,IAAXyF,EACbM,GAAO7B,EAAI+B,EAEXF,GAAO7B,EAAI+B,CAEZ,CACD,OAAOF,CACR"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 2e347d0..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/string-format' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 9c8c978..8f10c41 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1", - "@stdlib/utils-library-manifest": "^0.2.0" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/math-base-special-floor": "^0.1.1", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..9f58e2e --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..73a12c8 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From d88b03fd6723b1e2a9d56f0c6e960b7532d42ff3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 14 Feb 2024 10:22:31 +0000 Subject: [PATCH 087/140] Update README.md for UMD bundle v0.2.0 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c3c56b..f2ff564 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ limitations under the License. To use in Observable, ```javascript -sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@umd/browser.js' ) +sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.0-umd/browser.js' ) ``` To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build: @@ -66,7 +66,7 @@ var sub2ind = require( 'path/to/vendor/umd/ndarray-base-sub2ind/index.js' ) To include the bundle in a webpage, ```html - + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -226,7 +226,7 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); - + + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -226,7 +231,7 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); - + - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index 73a12c8..0000000 --- a/stats_node.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3cb34bc2caa3e5cbafd7b67930da2646e933f416 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:36:52 +0000 Subject: [PATCH 091/140] 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 | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 63 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 53 files changed, 9732 insertions(+), 6132 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index b6feb4d..39c935e 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,40 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.0", - "@stdlib/math-base-special-floor": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-base-shape2strides": "^0.2.0", - "@stdlib/ndarray-base-strides2offset": "^0.2.0", - "@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.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -94,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From f484449d72543cb71d955f2e969c4515df812d02 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 22 Feb 2024 03:55:24 +0000 Subject: [PATCH 092/140] Update README.md for UMD bundle v0.2.1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 18df67b..da85363 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ limitations under the License. To use in Observable, ```javascript -sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@umd/browser.js' ) +sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.1-umd/browser.js' ) ``` To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build: @@ -66,7 +66,7 @@ var sub2ind = require( 'path/to/vendor/umd/ndarray-base-sub2ind/index.js' ) To include the bundle in a webpage, ```html - + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -226,7 +226,7 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); - + + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -226,7 +231,7 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); - + - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b7f1aa10daef4435f63372bd82240c83ffc33fbb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 03:38:38 +0000 Subject: [PATCH 096/140] 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 | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 9732 insertions(+), 6135 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8e3ff96..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T01:27:25.253Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index be68c3a..39c935e 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 3da80dbb034f6fc71c647889e2cd4414554f3b2c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 01:43:31 +0000 Subject: [PATCH 097/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index c8caa61..235f2b5 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-library-manifest": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From 425327f5a8e112242b2fd3f23fae9744109878e0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:50:31 +0000 Subject: [PATCH 098/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d5893fab037a366dbe3a47a6f55e352df20036c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 03:50:43 +0000 Subject: [PATCH 099/140] 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 | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 9732 insertions(+), 6138 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 296cd5e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T01:15:09.650Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 235f2b5..39c935e 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From d70f934fb151efadbe66f56fcd6c545cc2bc4538 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 21:49:25 +0000 Subject: [PATCH 100/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index c8caa61..235f2b5 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-library-manifest": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From 236192c6c03bf0c986ddb0dbbc89901d0afa6943 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 23:51:12 +0000 Subject: [PATCH 101/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fbb597d82a86389c6f1f2213f3adade431519b3f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 11 Apr 2024 23:51:26 +0000 Subject: [PATCH 102/140] 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 | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 53 files changed, 9732 insertions(+), 6139 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 235f2b5..39c935e 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 21f9724db61bad5f90653bb5f6a02c7759d1b28e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 01:44:00 +0000 Subject: [PATCH 103/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index c8caa61..235f2b5 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-library-manifest": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From c249fb3a996da8811304ecff9c90a43f050b8de4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 03:15:26 +0000 Subject: [PATCH 104/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9020a3d26f2f3a3a9dccd96421c9b13ce4da84d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 May 2024 03:15:40 +0000 Subject: [PATCH 105/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 248 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 9732 insertions(+), 6147 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8725c40..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-05-01T01:15:55.483Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 235f2b5..39c935e 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From b96e2e4104eabacab906acbaa6859b624f57dd5b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 01:54:53 +0000 Subject: [PATCH 106/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index c8caa61..235f2b5 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-library-manifest": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From c79e12631bfa20f2a20682acf4bf46510dfaa011 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 03:19:52 +0000 Subject: [PATCH 107/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7e43af37b5cb9c78f3d89eb93359f45a0b01b13d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jun 2024 03:20:06 +0000 Subject: [PATCH 108/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 248 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 9732 insertions(+), 6147 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 20f2372..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-06-01T01:27:38.729Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 235f2b5..39c935e 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 3b22bd40e9664ecaec0c30fa8149cde81cd1c3e3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 01:52:25 +0000 Subject: [PATCH 109/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index c8caa61..235f2b5 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/utils-library-manifest": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" From c5f902c69b19521353d603dd2b232856a8157e04 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 03:21:05 +0000 Subject: [PATCH 110/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cb93d2fb97c9b8ba90ed9c220fb7a507c2a3334c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jul 2024 03:21:23 +0000 Subject: [PATCH 111/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 38 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 9732 insertions(+), 6184 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 78cf94f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-07-01T01:24:27.843Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 235f2b5..39c935e 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 59fbf516a782f063433ee41be838b370fb075673 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:11:49 +0000 Subject: [PATCH 112/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index 21346d0..75051b3 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-library-manifest": "^0.2.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 20820032a01d9a6f0f6b198d997c3cd823c0de02 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:30:57 +0000 Subject: [PATCH 113/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From b2b95a524cf46ab24e844af49609d58c0fa37dcd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:31:17 +0000 Subject: [PATCH 114/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 218 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 665 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 53 files changed, 9732 insertions(+), 6363 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 733f997..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,665 +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. -*/ - -/** -* Benchmark `sub2ind`. -*/ -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random double on the interval [0,1]. -* -* @return random double -*/ -double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 75051b3..f093420 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-floor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 31c91fab151e166fa3dd95248dac8bafc5b11025 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 27 Jul 2024 02:46:05 +0000 Subject: [PATCH 115/140] Update README.md for UMD bundle v0.2.2 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 76e355a..236a3cd 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ limitations under the License. To use in Observable, ```javascript -sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@umd/browser.js' ) +sub2ind = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-sub2ind@v0.2.2-umd/browser.js' ) ``` To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build: @@ -66,7 +66,7 @@ var sub2ind = require( 'path/to/vendor/umd/ndarray-base-sub2ind/index.js' ) To include the bundle in a webpage, ```html - + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -226,7 +226,7 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); - + + ``` If no recognized module system is present, access bundle contents via the global scope: @@ -226,7 +231,7 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); - + - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ae6ebfdd2c8cb27f14769ab978716a0be0332ef2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 03:50:01 +0000 Subject: [PATCH 119/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 168 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 662 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 9732 insertions(+), 6313 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index a3156e4..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T01:28:47.425Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 80c6fc3..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,662 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 78ba9db..f093420 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From e98d143dec11d099fda9ca32adabf2a9459a2b84 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 16:36:34 +0000 Subject: [PATCH 120/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index cb83e2a..78ba9db 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/utils-library-manifest": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From a9205aa0fe6d20d9416f04cb93fb49a66fdb7ed5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 17:40:33 +0000 Subject: [PATCH 121/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5f9c5a22349bc2eb695043163f7a701c78d431ba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 3 Aug 2024 17:40:49 +0000 Subject: [PATCH 122/140] 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 | 252 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 662 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 9732 insertions(+), 6397 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index d4fd424..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-03T16:15:09.374Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 80c6fc3..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,662 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 78ba9db..f093420 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From fc8d700935bc446dc9d813d8148166d96e173ebb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 02:02:16 +0000 Subject: [PATCH 123/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index d280c6c..f2d9ccf 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-library-manifest": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 5c7ac1e8111044e007cc4e66e421afad4b9c2c9b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 03:42:56 +0000 Subject: [PATCH 124/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 32364c4067ecea57a6b426a63b0685e001352faa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Sep 2024 03:43:15 +0000 Subject: [PATCH 125/140] 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 | 251 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 662 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 9732 insertions(+), 6396 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index c5916b6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-09-01T01:35:42.865Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 80c6fc3..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,662 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index f2d9ccf..f093420 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 62af5d77dbc85e65597e25ab6e8a1a9679fed70e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 02:07:29 +0000 Subject: [PATCH 126/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index d280c6c..f2d9ccf 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-library-manifest": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 77d7660010aaee11d7925c10f203025af2d4502f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 03:38:42 +0000 Subject: [PATCH 127/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 47aafb30d0cf324b68bb301143768e344ba0d825 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Oct 2024 03:38:59 +0000 Subject: [PATCH 128/140] 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 | 251 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 662 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 9732 insertions(+), 6396 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ee15d93..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-10-01T01:42:09.526Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 80c6fc3..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,662 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index f2d9ccf..f093420 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 5ebb07691d3b98090a20fb0134e825a376bdece8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 02:04:17 +0000 Subject: [PATCH 129/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index d280c6c..f2d9ccf 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/utils-library-manifest": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 812db8280d065fa3a48947c99c5b2d45008eef6e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 03:33:01 +0000 Subject: [PATCH 130/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bb543087f5be5c55d0e7203e6938f14de64aa9f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Nov 2024 03:33:15 +0000 Subject: [PATCH 131/140] 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 | 251 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 662 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 +++++++++++++++++++++ stats_node.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 54 files changed, 9732 insertions(+), 6396 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 8a7344c..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-11-01T01:39:18.553Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 80c6fc3..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,662 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index f2d9ccf..f093420 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 358a3069d5f2454039541e63ff26af760de0c44c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 02:10:48 +0000 Subject: [PATCH 132/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index 6b2705c..7d8add9 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-library-manifest": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From b8b9ef4f14bad28dd3adc6c1c9ee19c95b616e68 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 03:38:27 +0000 Subject: [PATCH 133/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3e284586e64613be90dd6d014c6e47906052b845 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Dec 2024 03:38:54 +0000 Subject: [PATCH 134/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 251 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 662 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 ++++++++++++++++++ stats_node.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 55 files changed, 9732 insertions(+), 6501 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 95367f6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-01T01:45:50.498Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 80c6fc3..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,662 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 7d8add9..f093420 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 1fc220c6ab74c1202b082c2526d4f162e1e4379d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 03:09:14 +0000 Subject: [PATCH 135/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index 6b2705c..7d8add9 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-library-manifest": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From 9ada1f43e2656dfe1230f01f7a190884bb590318 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 04:22:33 +0000 Subject: [PATCH 136/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6b7dbf8b0688ee67235c1e2da161c89a6461a9b6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 04:22:46 +0000 Subject: [PATCH 137/140] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 251 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 662 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 ++++++++++++++++++ stats_node.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 55 files changed, 9732 insertions(+), 6501 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 56e3fb2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T02:44:35.448Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 80c6fc3..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,662 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..ccfea70 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea30711 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 7d8add9..f093420 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); From 97dab619c2f62326eed959689bb87e7d2c86a2dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 00:55:26 +0000 Subject: [PATCH 138/140] Transform error messages --- lib/main.js | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 2e347d0..298dd1b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); // MAIN // @@ -176,7 +176,7 @@ function sub2ind() { j += m; } if ( j < 0 || j >= m ) { - throw new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) ); + throw new RangeError( format( '0jX5J', i, j ) ); } } s = strides[ i ]; diff --git a/package.json b/package.json index 6b2705c..7d8add9 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ }, "dependencies": { "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/utils-library-manifest": "^0.2.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" From a26df94dc0ca613df6421de433d55d18defd441c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 01:19:21 +0000 Subject: [PATCH 139/140] Remove files --- browser.js | 3 - browser.js.map | 1 - index.js | 3 - index.js.map | 1 - stats_browser.html | 4842 -------------------------------------------- stats_node.html | 4842 -------------------------------------------- 6 files changed, 9692 deletions(-) delete mode 100644 browser.js delete mode 100644 browser.js.map delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 stats_browser.html delete mode 100644 stats_node.html diff --git a/browser.js b/browser.js deleted file mode 100644 index ccfea70..0000000 --- a/browser.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map deleted file mode 100644 index fafdc57..0000000 --- a/browser.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index ea30711..0000000 --- a/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); -//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map deleted file mode 100644 index 2629027..0000000 --- a/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/stats_browser.html b/stats_browser.html deleted file mode 100644 index 43e9ffc..0000000 --- a/stats_browser.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - diff --git a/stats_node.html b/stats_node.html deleted file mode 100644 index c640583..0000000 --- a/stats_node.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 871ad3a2e71246815f7dac93fecfc5f3ec1d6527 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 3 Feb 2025 01:19:37 +0000 Subject: [PATCH 140/140] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 251 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 62 +- SECURITY.md | 5 - benchmark/benchmark.js | 478 -- benchmark/c/Makefile | 146 - benchmark/c/benchmark.c | 662 --- benchmark/julia/REQUIRE | 2 - benchmark/julia/benchmark.jl | 144 - benchmark/python/numpy/benchmark.py | 97 - branches.md | 56 - browser.js | 3 + browser.js.map | 1 + dist/index.d.ts | 3 - dist/index.js | 5 - dist/index.js.map | 7 - docs/repl.txt | 56 - docs/types/index.d.ts | 131 - docs/types/test.ts | 97 - examples/index.js | 65 - include/stdlib/ndarray/base/sub2ind.h | 41 - index.js | 3 + index.js.map | 1 + lib/index.js | 45 - lib/main.js | 197 - manifest.json | 40 - package.json | 64 +- src/main.c | 110 - stats_browser.html | 4842 ++++++++++++++++++ stats_node.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 463 -- 55 files changed, 9732 insertions(+), 6500 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/c/Makefile delete mode 100644 benchmark/c/benchmark.c delete mode 100644 benchmark/julia/REQUIRE delete mode 100644 benchmark/julia/benchmark.jl delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md create mode 100644 browser.js create mode 100644 browser.js.map delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 include/stdlib/ndarray/base/sub2ind.h create mode 100644 index.js create mode 100644 index.js.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 manifest.json delete mode 100644 src/main.c create mode 100644 stats_browser.html create mode 100644 stats_node.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6e14367..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-03T00:48:09.425Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index b09e382..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 7a4c103..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/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 b9a6211..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 12 * * 0' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n +``` -```javascript -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +If no recognized module system is present, access bundle contents via the global scope: + +```html + ``` #### sub2ind( shape, strides, offset, ...subscripts, mode ) @@ -211,13 +217,18 @@ idx = sub2ind( shape, strides, offset, 10, 10, mode ); -```javascript -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); +```html + + + + + + + + + + + + ```
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 0145231..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,478 +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 shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var pkg = require( './../package.json' ).name; -var sub2ind = require( './../lib' ); - - -// MAIN // - -bench( pkg+':mode=[throw]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'throw' ]; - - 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, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'wrap' ]; - - 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()*100.0 ) - 50.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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],offset=0', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - for ( i = 0; i < shape.length; i++ ) { - strides[ i ] *= -1; - } - offset = 0; - mode = [ 'normalize' ]; - - 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()*20.0 ) - 10.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'wrap', 'clamp', 'clamp' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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 strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== out ) { - b.fail( '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,wrap]', function benchmark( b ) { - var strides; - var offset; - var shape; - var mode; - var out; - var s0; - var s1; - var s2; - var i; - - shape = [ 10, 10, 10 ]; - strides = shape2strides( shape, 'row-major' ); - offset = strides2offset( shape, strides ); - mode = [ 'clamp', 'wrap', 'wrap' ]; - - 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()*20.0 ) - 5.0; - out = sub2ind( shape, strides, offset, s0, s1, s2, mode ); - if ( out !== 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/c/Makefile b/benchmark/c/Makefile deleted file mode 100644 index c12ea19..0000000 --- a/benchmark/c/Makefile +++ /dev/null @@ -1,146 +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. -#/ - -# VARIABLES # - -ifndef VERBOSE - QUIET := @ -else - QUIET := -endif - -# Determine the OS ([1][1], [2][2]). -# -# [1]: https://en.wikipedia.org/wiki/Uname#Examples -# [2]: http://stackoverflow.com/a/27776822/2225624 -OS ?= $(shell uname) -ifneq (, $(findstring MINGW,$(OS))) - OS := WINNT -else -ifneq (, $(findstring MSYS,$(OS))) - OS := WINNT -else -ifneq (, $(findstring CYGWIN,$(OS))) - OS := WINNT -else -ifneq (, $(findstring Windows_NT,$(OS))) - OS := WINNT -endif -endif -endif -endif - -# Define the program used for compiling C source files: -ifdef C_COMPILER - CC := $(C_COMPILER) -else - CC := gcc -endif - -# Define the command-line options when compiling C files: -CFLAGS ?= \ - -std=c99 \ - -O3 \ - -Wall \ - -pedantic - -# Determine whether to generate position independent code ([1][1], [2][2]). -# -# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options -# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option -ifeq ($(OS), WINNT) - fPIC ?= -else - fPIC ?= -fPIC -endif - -# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): -INCLUDE ?= - -# List of source files: -SOURCE_FILES ?= - -# List of libraries (e.g., `-lopenblas -lpthread`): -LIBRARIES ?= - -# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): -LIBPATH ?= - -# List of C targets: -c_targets := benchmark.out - - -# RULES # - -#/ -# Compiles C source files. -# -# @param {string} SOURCE_FILES - list of C source files -# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {string} [LIBRARIES] - list of libraries (e.g., `-lpthread -lblas`) -# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} [C_COMPILER] - C compiler -# @param {string} [CFLAGS] - C compiler flags -# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code -# -# @example -# make -# -# @example -# make all -#/ -all: $(c_targets) - -.PHONY: all - -#/ -# Compiles C source files. -# -# @private -# @param {string} SOURCE_FILES - list of C source files -# @param {(string|void)} INCLUDE - list of includes (e.g., `-I /foo/bar -I /beep/boop`) -# @param {(string|void)} LIBRARIES - list of libraries (e.g., `-lpthread -lblas`) -# @param {(string|void)} LIBPATH - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) -# @param {string} CC - C compiler -# @param {string} CFLAGS - C compiler flags -# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code -#/ -$(c_targets): %.out: %.c - $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) - -#/ -# Runs compiled benchmarks. -# -# @example -# make run -#/ -run: $(c_targets) - $(QUIET) ./$< - -.PHONY: run - -#/ -# Removes generated files. -# -# @example -# make clean -#/ -clean: - $(QUIET) -rm -f *.o *.out - -.PHONY: clean diff --git a/benchmark/c/benchmark.c b/benchmark/c/benchmark.c deleted file mode 100644 index 80c6fc3..0000000 --- a/benchmark/c/benchmark.c +++ /dev/null @@ -1,662 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include -#include -#include -#include -#include -#include - -#define NAME "sub2ind" -#define ITERATIONS 1000000 -#define REPEATS 3 - -/** -* Prints the TAP version. -*/ -static void print_version( void ) { - printf( "TAP version 13\n" ); -} - -/** -* Prints the TAP summary. -* -* @param total total number of tests -* @param passing total number of passing tests -*/ -static void print_summary( int total, int passing ) { - printf( "#\n" ); - printf( "1..%d\n", total ); // TAP plan - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); -} - -/** -* Prints benchmarks results. -* -* @param elapsed elapsed time in seconds -*/ -static void print_results( double elapsed ) { - double rate = (double)ITERATIONS / elapsed; - printf( " ---\n" ); - printf( " iterations: %d\n", ITERATIONS ); - printf( " elapsed: %0.9f\n", elapsed ); - printf( " rate: %0.9f\n", rate ); - printf( " ...\n" ); -} - -/** -* Returns a clock time. -* -* @return clock time -*/ -static double tic( void ) { - struct timeval now; - gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; -} - -/** -* Generates a random number on the interval [0,1). -* -* @return random number -*/ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark1( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark2( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_ERROR - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( rand_double()*10.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark3( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark4( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark5( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark6( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0) - 5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark7( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark8( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_CLAMP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark9( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark10( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_CLAMP, - STDLIB_NDARRAY_INDEX_WRAP, - STDLIB_NDARRAY_INDEX_WRAP - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*20.0)-5.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark11( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { 100, 10, 1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0)-1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @return elapsed time in seconds -*/ -static double benchmark12( void ) { - double elapsed; - int64_t idx; - double t; - int i; - - int64_t ndims = 3; - int64_t shape[] = { 10, 10, 10 }; - int64_t strides[] = { -100, -10, -1 }; - int64_t offset = 0; - - int64_t sub[] = { 5, 5, 5 }; - - int64_t nmodes = 1; - int8_t modes[] = { - STDLIB_NDARRAY_INDEX_NORMALIZE - }; - - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - sub[ 2 ] = (int64_t)( (rand_double()*2000.0) - 1000.0 ); - idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); - if ( idx < -1 ) { - printf( "unexpected result\n" ); - break; - } - } - elapsed = tic() - t; - if ( idx < -1 ) { - printf( "unexpected result\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int i; - - count = 0; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error]\n", NAME ); - elapsed = benchmark1(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[error],offset=0\n", NAME ); - elapsed = benchmark2(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap]\n", NAME ); - elapsed = benchmark3(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap],offset=0\n", NAME ); - elapsed = benchmark4(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp]\n", NAME ); - elapsed = benchmark5(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp],offset=0\n", NAME ); - elapsed = benchmark6(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp]\n", NAME ); - elapsed = benchmark7(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[wrap,clamp,clamp]\n", NAME ); - elapsed = benchmark8(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap]\n", NAME ); - elapsed = benchmark9(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[clamp,wrap,wrap]\n", NAME ); - elapsed = benchmark10(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize]\n", NAME ); - elapsed = benchmark11(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - for ( i = 0; i < REPEATS; i++ ) { - count += 1; - printf( "# c::native::%s:mode=[normalize],offset=0\n", NAME ); - elapsed = benchmark12(); - print_results( elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - print_summary( count, count ); -} 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 26da902..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind" -%% click B href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/sub2ind -[production-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-base-sub2ind/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-base-sub2ind/blob/esm/README.md \ No newline at end of file diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..44cdaa8 --- /dev/null +++ b/browser.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=browser.js.map diff --git a/browser.js.map b/browser.js.map new file mode 100644 index 0000000..fafdc57 --- /dev/null +++ b/browser.js.map @@ -0,0 +1 @@ +{"version":3,"file":"browser.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ 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 98858aa..0000000 --- a/dist/index.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict";var g=function(i,s){return function(){return s||i((s={exports:{}}).exports,s),s.exports}};var l=g(function(x,d){ -var c=require('@stdlib/error-tools-fmtprodmsg/dist');function p(){var i,s,o,f,m,v,t,n,e,u,r,a;for(f=arguments[0],i=arguments[1],s=arguments[2],m=f.length,v=arguments[3+m],o=v.length,n=s,a=0;a=e&&(r=e-1);else if(t==="wrap")r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e))):r>=e&&(r-=e,r>=e&&(r%=e));else if(t==="normalize"&&r<0&&(r+=e),r<0||r>=e)throw new RangeError(c('0jX5J',a,r));u=i[a],u<0&&s===0?n-=r*u:n+=r*u}return n}d.exports=p -});var b=l();module.exports=b; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 474ac32..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 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\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( 'invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\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-base-sub2ind\n*\n* @example\n* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' );\n*\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ];\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\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,cAsBA,IAAIC,EAAS,QAAS,uBAAwB,EAyG9C,SAASC,GAAU,CAClB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,IAPAR,EAAQ,UAAW,CAAE,EACrBH,EAAU,UAAW,CAAE,EACvBC,EAAS,UAAW,CAAE,EACtBG,EAAQD,EAAM,OACdE,EAAQ,UAAW,EAAED,CAAM,EAC3BF,EAASG,EAAM,OACfE,EAAMN,EACAU,EAAI,EAAGA,EAAIP,EAAOO,IAAM,CAI7B,GAHAH,EAAIL,EAAOQ,CAAE,EACbD,EAAI,UAAWC,EAAE,CAAE,EACnBL,EAAOD,EAAOM,EAAET,CAAO,EAClBI,IAAS,QACRI,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,WAEEF,IAAS,OACfI,EAAI,GACRA,GAAKF,EACAE,EAAI,IACRA,GAAKF,EACAE,IAAM,IACVA,GAAKF,KAGIE,GAAKF,IAChBE,GAAKF,EACAE,GAAKF,IACTE,GAAKF,YAIFF,IAAS,aAAeI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAI,WAAYV,EAAQ,+FAAgGa,EAAGD,CAAE,CAAE,EAGvID,EAAIT,EAASW,CAAE,EAGVF,EAAI,GAAKR,IAAW,EACxBM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEb,CACA,OAAOF,CACR,CAKAV,EAAO,QAAUE,IC7JjB,IAAIa,EAAU,IAKd,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "format", "sub2ind", "strides", "offset", "nmodes", "shape", "ndims", "modes", "mode", "idx", "m", "s", "j", "i", "sub2ind"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index f254c8c..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,56 +0,0 @@ - -{{alias}}( shape, strides, offset, ...subscript, mode ) - Converts subscripts to a linear index. - - When provided a stride array containing negative strides, if an `offset` is - greater than `0`, the function treats subscripts as mapping to a linear - index in an underlying data buffer for the array, thus returning a linear - index from the perspective of that buffer. If an `offset` is equal to `0`, - the function treats subscripts as mapping to a linear index in an array - view, thus returning a linear index from the perspective of that view. In - short, from the perspective of a view, view data is always ordered. - - When provided fewer modes than dimensions, the function recycles modes using - modulo arithmetic. - - Parameters - ---------- - shape: ArrayLike - Array shape. - - strides: ArrayLike - Stride array. - - offset: integer - Location of the first indexed value based on the stride array. - - subscript: ...integer - Subscripts. - - mode: Array - Specifies how to handle subscripts which exceed array dimensions for - each dimension. If the mode for a dimension is 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. - - Returns - ------- - idx: integer - Linear index. - - Examples - -------- - > var d = [ 3, 3, 3 ]; - > var s = [ 9, 3, 1 ]; - > var o = 0; - > var idx = {{alias}}( d, s, o, 1, 2, 2, [ 'throw' ] ) - 17 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 1dd968a..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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'; - -/** -* 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* -* @param shape - array shape -* @param strides - stride array -* @param offset - location of the first indexed value **based** on the stride array -* @param args - subscripts followed by a `mode` specifying how to handle subscripts which exceed array dimensions -* @param mode - specifies how to handle subscripts which exceed array dimensions -* @throws must provide subscripts which do not exceed array dimensions -* @returns linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns 17 -*/ -declare function sub2ind( shape: ArrayLike, strides: ArrayLike, offset: number, ...args: Array> ): number; - - -// EXPORTS // - -export = sub2ind; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e86ea32..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT 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 sub2ind = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - const mode = [ 'throw' ]; - sub2ind( shape, strides, offset, 1, 2, 2, mode ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers... -{ - const strides = [ 10, 1 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( true, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( false, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( null, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( undefined, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( '5', strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( [ '1', '2' ], strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( {}, strides, offset, 0, 0, mode ); // $ExpectError - sub2ind( ( x: number ): number => x, strides, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... -{ - const shape = [ 3, 3, 3 ]; - const offset = 10; - const mode = [ 'throw' ]; - sub2ind( shape, true, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, false, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, null, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, undefined, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, '5', offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, [ '1', '2' ], offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, {}, offset, 0, 0, mode ); // $ExpectError - sub2ind( shape, ( x: number ): number => x, offset, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a number... -{ - const shape = [ 10, 10 ]; - const strides = [ 10, 1 ]; - const mode = [ 'throw' ]; - sub2ind( shape, strides, true, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, false, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, null, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, undefined, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, '5', 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, [ '1', '2' ], 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, {}, 0, 0, mode ); // $ExpectError - sub2ind( shape, strides, ( x: number ): number => x, 0, 0, mode ); // $ExpectError -} - -// The compiler throws an error if the function is provided further arguments which are not numbers followed by an array of strings... -{ - const shape = [ 3, 3, 3 ]; - const strides = [ 9, 3, 1 ]; - const offset = 0; - sub2ind( shape, strides, offset, true ); // $ExpectError - sub2ind( shape, strides, offset, false ); // $ExpectError - sub2ind( shape, strides, offset, null ); // $ExpectError - sub2ind( shape, strides, offset, undefined ); // $ExpectError - sub2ind( shape, strides, offset, 'abc' ); // $ExpectError - sub2ind( shape, strides, offset, {} ); // $ExpectError - sub2ind( shape, strides, offset, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided insufficient arguments... -{ - sub2ind(); // $ExpectError - sub2ind( [ 10, 10 ] ); // $ExpectError - sub2ind( [ 10, 10 ], [ 10, 1 ] ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 19313bb..0000000 --- a/examples/index.js +++ /dev/null @@ -1,65 +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 discreteUniform = require( '@stdlib/random-base-discrete-uniform' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var randu = require( '@stdlib/random-base-randu' ); -var sub2ind = require( './../lib' ); - -var shape = [ 3, 3 ]; -var strides = shape2strides( shape, 'row-major' ); -var mode = 'throw'; -var len = numel( shape ); - -var arr = []; -var i; -for ( i = 0; i < len; i++ ) { - arr.push( i ); -} - -var offset; -var idx; -var row; -var j; -var n; -var m; -for ( i = 0; i < 20; i++ ) { - j = discreteUniform( 0, shape.length-1 ); - strides[ j ] *= ( randu() < 0.5 ) ? -1 : 1; - offset = strides2offset( shape, strides ); - - console.log( '' ); - console.log( 'Dimensions: %s.', shape.join( 'x' ) ); - console.log( 'Strides: %s.', strides.join( ',' ) ); - console.log( 'View:' ); - for ( n = 0; n < shape[ 0 ]; n++ ) { - row = ' '; - for ( m = 0; m < shape[ 1 ]; m++ ) { - idx = sub2ind( shape, strides, offset, n, m, mode ); - row += arr[ idx ]; - if ( m < shape[ 1 ]-1 ) { - row += ', '; - } - } - console.log( row ); - } -} diff --git a/include/stdlib/ndarray/base/sub2ind.h b/include/stdlib/ndarray/base/sub2ind.h deleted file mode 100644 index cbb2899..0000000 --- a/include/stdlib/ndarray/base/sub2ind.h +++ /dev/null @@ -1,41 +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. -*/ - -#ifndef STDLIB_NDARRAY_BASE_SUB2IND_H -#define STDLIB_NDARRAY_BASE_SUB2IND_H - -#include "stdlib/ndarray/index_modes.h" -#include - -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Converts subscripts to a linear index. -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ); - -#ifdef __cplusplus -} -#endif - -#endif // !STDLIB_NDARRAY_BASE_SUB2IND_H diff --git a/index.js b/index.js new file mode 100644 index 0000000..ea9fab0 --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +var e,n;e=this,n=function(){"use strict";function e(){var e,n=arguments,t="https://stdlib.io/e/"+n[0]+"?";for(e=1;e=s&&(a=s-1);else if("wrap"===l)a<0?(a+=s)<0&&0!=(a%=s)&&(a+=s):a>=s&&(a-=s)>=s&&(a%=s);else if("normalize"===l&&a<0&&(a+=s),a<0||a>=s)throw new RangeError(e("0jX5J",p,a));(u=n[p])<0&&0===t?d-=a*u:d+=a*u}return d}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).sub2ind=n(); +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..2629027 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../node_modules/@stdlib/error-tools-fmtprodmsg/lib/main.js","../lib/main.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MAIN //\n\n/**\n* Formats an error message for production.\n*\n* @param {string} code - error code\n* @param {*} ...args - error message arguments\n* @returns {string} formatted error message\n*\n* @example\n* var msg = fmtprodmsg( '3', 'wrong_type' );\n* // returns 'https://stdlib.io/e/3?&arg[]=wrong_type'\n*/\nfunction fmtprodmsg() {\n\tvar a = arguments;\n\tvar c = a[ 0 ];\n\tvar u = 'https://stdlib.io/e/'+c+'?';\n\tvar i;\n\tfor ( i = 1; i < a.length; i++ ) {\n\t\tu += '&arg[]=' + encodeURIComponent( a[ i ] );\n\t}\n\treturn u;\n}\n\n\n// EXPORTS //\n\nexport default fmtprodmsg;\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 format from '@stdlib/error-tools-fmtprodmsg';\n\n\n// MAIN //\n\n/**\n* Converts subscripts to a linear index.\n*\n* ## Notes\n*\n* - The function accepts the following \"modes\":\n*\n* - **throw**: throw an error when a subscript exceeds array dimensions.\n* - **normalize**: normalize negative subscripts and throw an error when a subscript exceeds array dimensions.\n* - **wrap**: wrap around subscripts exceeding array dimensions using modulo arithmetic.\n* - **clamp**: set subscripts exceeding array dimensions to either `0` (minimum index) or the maximum index along a particular dimension.\n*\n* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic.\n*\n* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view.\n*\n* ```text\n* Dims: 2x2\n* Buffer: [ 1, 2, 3, 4 ]\n*\n* View = [ a00, a01,\n* a10, a11 ]\n*\n* Strides: 2,1\n* Offset: 0\n*\n* View = [ 1, 2,\n* 3, 4 ]\n*\n* Strides: 2,-1\n* Offset: 1\n*\n* View = [ 2, 1,\n* 4, 3 ]\n*\n* Strides: -2,1\n* Offset: 2\n*\n* View = [ 3, 4,\n* 1, 2 ]\n*\n* Strides: -2,-1\n* Offset: 3\n*\n* View = [ 4, 3,\n* 2, 1 ]\n* ```\n*\n* ```javascript\n* var shape = [ 2, 2 ];\n* var strides = [ -2, 1 ];\n* var offset = 2;\n* var mode = [ 'throw' ];\n*\n* // From the perspective of a view...\n* var idx = sub2ind( shape, strides, 0, 0, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, 0, 0, 1, mode );\n* // returns 1\n*\n* idx = sub2ind( shape, strides, 0, 1, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, 0, 1, 1, mode );\n* // returns 3\n*\n* // From the perspective of an underlying buffer...\n* idx = sub2ind( shape, strides, offset, 0, 0, mode );\n* // returns 2\n*\n* idx = sub2ind( shape, strides, offset, 0, 1, mode );\n* // returns 3\n*\n* idx = sub2ind( shape, strides, offset, 1, 0, mode );\n* // returns 0\n*\n* idx = sub2ind( shape, strides, offset, 1, 1, mode );\n* // returns 1\n* ```\n*\n* In short, from the perspective of a view, view data is always ordered.\n*\n* @param {NonNegativeIntegerArray} shape - array shape\n* @param {IntegerArray} strides - stride array\n* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array\n* @param {...integer} i - subscripts\n* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions\n* @throws {RangeError} must provide subscripts which do not exceed array dimensions\n* @returns {NonNegativeInteger} linear index\n*\n* @example\n* var shape = [ 3, 3, 3 ];\n* var strides = [ 9, 3, 1 ];\n* var offset = 0;\n* var mode = [ 'throw' ]\n*\n* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode );\n* // returns [ 'throw' ]\n*/\nfunction sub2ind() {\n\tvar strides;\n\tvar offset;\n\tvar nmodes;\n\tvar shape;\n\tvar ndims;\n\tvar modes;\n\tvar mode;\n\tvar idx;\n\tvar m;\n\tvar s;\n\tvar j;\n\tvar i;\n\n\tshape = arguments[ 0 ];\n\tstrides = arguments[ 1 ];\n\toffset = arguments[ 2 ];\n\tndims = shape.length;\n\tmodes = arguments[ 3+ndims ]; // last argument\n\tnmodes = modes.length;\n\tidx = offset;\n\tfor ( i = 0; i < ndims; i++ ) {\n\t\tm = shape[ i ];\n\t\tj = arguments[ i+3 ];\n\t\tmode = modes[ i%nmodes ];\n\t\tif ( mode === 'clamp' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj = 0;\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj = m - 1;\n\t\t\t}\n\t\t} else if ( mode === 'wrap' ) {\n\t\t\tif ( j < 0 ) {\n\t\t\t\tj += m; // slight optimization to avoid modulo arithmetic when |j| <= m\n\t\t\t\tif ( j < 0 ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\t\tj += m;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if ( j >= m ) {\n\t\t\t\tj -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m\n\t\t\t\tif ( j >= m ) {\n\t\t\t\t\tj %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif ( mode === 'normalize' && j < 0 ) {\n\t\t\t\tj += m;\n\t\t\t}\n\t\t\tif ( j < 0 || j >= m ) {\n\t\t\t\tthrow new RangeError( format( '0jX5J', i, j ) );\n\t\t\t}\n\t\t}\n\t\ts = strides[ i ];\n\n\t\t// Check if array view...\n\t\tif ( s < 0 && offset === 0 ) {\n\t\t\tidx -= j * s; // increments idx\n\t\t} else {\n\t\t\tidx += j * s; // may increment or decrement idx\n\t\t}\n\t}\n\treturn idx;\n}\n\n\n// EXPORTS //\n\nexport default sub2ind;\n"],"names":["fmtprodmsg","i","a","arguments","u","length","encodeURIComponent","strides","offset","nmodes","shape","ndims","modes","mode","idx","m","s","j","RangeError","format"],"mappings":";yCAiCA,SAASA,IACR,IAGIC,EAHAC,EAAIC,UAEJC,EAAI,uBADAF,EAAG,GACsB,IAEjC,IAAMD,EAAI,EAAGA,EAAIC,EAAEG,OAAQJ,IAC1BG,GAAK,UAAYE,mBAAoBJ,EAAGD,IAEzC,OAAOG,CACR,QCqFA,WACC,IAAIG,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EASJ,IANAM,EAAUJ,UAAW,GACrBK,EAASL,UAAW,GAGpBM,GADAG,EAAQT,UAAW,GADnBQ,GAHAD,EAAQP,UAAW,IAGLE,UAECA,OACfS,EAAMN,EACAP,EAAI,EAAGA,EAAIU,EAAOV,IAAM,CAI7B,GAHAc,EAAIL,EAAOT,GACXgB,EAAId,UAAWF,EAAE,GAEH,WADdY,EAAOD,EAAOX,EAAEQ,IAEVQ,EAAI,EACRA,EAAI,EACOA,GAAKF,IAChBE,EAAIF,EAAI,QAEH,GAAc,SAATF,EACNI,EAAI,GACRA,GAAKF,GACI,GAEG,IADXE,GAAKF,KAEJE,GAAKF,GAGIE,GAAKF,IAChBE,GAAKF,IACKA,IACTE,GAAKF,QAOP,GAHc,cAATF,GAAwBI,EAAI,IAChCA,GAAKF,GAEDE,EAAI,GAAKA,GAAKF,EAClB,MAAM,IAAIG,WAAYC,EAAQ,QAASlB,EAAGgB,KAG5CD,EAAIT,EAASN,IAGJ,GAAgB,IAAXO,EACbM,GAAOG,EAAID,EAEXF,GAAOG,EAAID,CAEZ,CACD,OAAOF,CACR","x_google_ignoreList":[0]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c49fcb7..0000000 --- a/lib/index.js +++ /dev/null @@ -1,45 +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-base-sub2ind -* -* @example -* var sub2ind = require( '@stdlib/ndarray-base-sub2ind' ); -* -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ]; -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // 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 298dd1b..0000000 --- a/lib/main.js +++ /dev/null @@ -1,197 +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 format = require( '@stdlib/error-tools-fmtprodmsg' ); - - -// 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. -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. -* -* ```text -* Dims: 2x2 -* Buffer: [ 1, 2, 3, 4 ] -* -* View = [ a00, a01, -* a10, a11 ] -* -* Strides: 2,1 -* Offset: 0 -* -* View = [ 1, 2, -* 3, 4 ] -* -* Strides: 2,-1 -* Offset: 1 -* -* View = [ 2, 1, -* 4, 3 ] -* -* Strides: -2,1 -* Offset: 2 -* -* View = [ 3, 4, -* 1, 2 ] -* -* Strides: -2,-1 -* Offset: 3 -* -* View = [ 4, 3, -* 2, 1 ] -* ``` -* -* ```javascript -* var shape = [ 2, 2 ]; -* var strides = [ -2, 1 ]; -* var offset = 2; -* var mode = [ 'throw' ]; -* -* // From the perspective of a view... -* var idx = sub2ind( shape, strides, 0, 0, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, 0, 0, 1, mode ); -* // returns 1 -* -* idx = sub2ind( shape, strides, 0, 1, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, 0, 1, 1, mode ); -* // returns 3 -* -* // From the perspective of an underlying buffer... -* idx = sub2ind( shape, strides, offset, 0, 0, mode ); -* // returns 2 -* -* idx = sub2ind( shape, strides, offset, 0, 1, mode ); -* // returns 3 -* -* idx = sub2ind( shape, strides, offset, 1, 0, mode ); -* // returns 0 -* -* idx = sub2ind( shape, strides, offset, 1, 1, mode ); -* // returns 1 -* ``` -* -* In short, from the perspective of a view, view data is always ordered. -* -* @param {NonNegativeIntegerArray} shape - array shape -* @param {IntegerArray} strides - stride array -* @param {NonNegativeInteger} offset - location of the first indexed value **based** on the stride array -* @param {...integer} i - subscripts -* @param {StringArray} mode - specifies how to handle subscripts which exceed array dimensions -* @throws {RangeError} must provide subscripts which do not exceed array dimensions -* @returns {NonNegativeInteger} linear index -* -* @example -* var shape = [ 3, 3, 3 ]; -* var strides = [ 9, 3, 1 ]; -* var offset = 0; -* var mode = [ 'throw' ] -* -* var idx = sub2ind( shape, strides, offset, 1, 2, 2, mode ); -* // returns [ 'throw' ] -*/ -function sub2ind() { - var strides; - var offset; - var nmodes; - var shape; - var ndims; - var modes; - var mode; - var idx; - var m; - var s; - var j; - var i; - - shape = arguments[ 0 ]; - strides = arguments[ 1 ]; - offset = arguments[ 2 ]; - ndims = shape.length; - modes = arguments[ 3+ndims ]; // last argument - nmodes = modes.length; - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = arguments[ i+3 ]; - mode = modes[ i%nmodes ]; - if ( mode === 'clamp' ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode === 'wrap' ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j %= m; - if ( j !== 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode === 'normalize' && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - throw new RangeError( format( '0jX5J', i, j ) ); - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset === 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} - - -// EXPORTS // - -module.exports = sub2ind; diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1c0cf86..0000000 --- a/manifest.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "options": {}, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/ndarray-index-modes" - ] - } - ] -} diff --git a/package.json b/package.json index 7d8add9..f093420 100644 --- a/package.json +++ b/package.json @@ -3,33 +3,7 @@ "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", - "include": "./include", - "lib": "./lib", - "src": "./src", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "main": "./index.js", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -38,41 +12,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/ndarray-index-modes": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/utils-library-manifest": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^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", @@ -95,7 +34,6 @@ "idx", "strided" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 212a5e7..0000000 --- a/src/main.c +++ /dev/null @@ -1,110 +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. -*/ - -#include "stdlib/ndarray/base/sub2ind.h" -#include "stdlib/ndarray/index_modes.h" -#include - -/** -* Converts subscripts to a linear index. -* -* ## Notes -* -* - When provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. -* - When provided a stride array containing negative strides, if an `offset` is greater than `0`, the function treats subscripts as mapping to a linear index in an underlying data buffer for the array, thus returning a linear index from the perspective of that buffer. If an `offset` is equal to `0`, the function treats subscripts as mapping to a linear index in an array view, thus returning a linear index from the perspective of that view. In short, from the perspective of a view, view data is always ordered. -* - In "error" mode, the function returns `-1` if a subscript is out-of-bounds. -* -* @param ndims number of dimensions -* @param shape array shape (dimensions) -* @param strides array strides -* @param offset location of the first indexed value **based** on the stride array -* @param sub subscripts -* @param nmodes number of modes -* @param modes specifies how to handle subscripts which exceed array dimensions -* @return linear index -* -* @example -* #include "stdlib/ndarray/index_modes.h" -* #include "stdlib/ndarray/base/sub2ind.h" -* -* int64_t ndims = 3; -* int64_t shape[] = { 3, 3, 3 }; -* int64_t strides[] = { 9, 3, 1 }; -* int64_t offset = 0; -* -* int64_t nmodes = 1; -* int8_t modes[] = { STDLIB_NDARRAY_INDEX_ERROR }; -* -* int64_t sub[] = { 1, 2, 2 }; -* -* int64_t idx = stdlib_ndarray_sub2ind( ndims, shape, strides, offset, sub, nmodes, modes ); -* // returns 17 -*/ -int64_t stdlib_ndarray_sub2ind( const int64_t ndims, const int64_t *shape, const int64_t *strides, const int64_t offset, const int64_t *sub, const int64_t nmodes, const int8_t *modes ) { - enum STDLIB_NDARRAY_INDEX_MODE mode; - int64_t idx; - int64_t s; - int64_t m; - int64_t j; - int64_t i; - - idx = offset; - for ( i = 0; i < ndims; i++ ) { - m = shape[ i ]; - j = sub[ i ]; - mode = modes[ i%nmodes ]; - if ( mode == STDLIB_NDARRAY_INDEX_CLAMP ) { - if ( j < 0 ) { - j = 0; - } else if ( j >= m ) { - j = m - 1; - } - } else if ( mode == STDLIB_NDARRAY_INDEX_WRAP ) { - if ( j < 0 ) { - j += m; // slight optimization to avoid modulo arithmetic when |j| <= m - if ( j < 0 ) { - j -= m*( (int64_t)( j/m ) ); // this is equivalent to `j mod m`, where the result has same sign as dividend (i.e., `j`); cannot use `%` as the sign of the result is implementation defined in C - if ( j != 0 ) { - j += m; - } - } - } else if ( j >= m ) { - j -= m; // slight optimization to avoid modulo arithmetic when m < j <= 2m - if ( j >= m ) { - j %= m; - } - } - } else { - if ( mode == STDLIB_NDARRAY_INDEX_NORMALIZE && j < 0 ) { - j += m; - } - if ( j < 0 || j >= m ) { - return -1; - } - } - s = strides[ i ]; - - // Check if array view... - if ( s < 0 && offset == 0 ) { - idx -= j * s; // increments idx - } else { - idx += j * s; // may increment or decrement idx - } - } - return idx; -} diff --git a/stats_browser.html b/stats_browser.html new file mode 100644 index 0000000..43e9ffc --- /dev/null +++ b/stats_browser.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/stats_node.html b/stats_node.html new file mode 100644 index 0000000..c640583 --- /dev/null +++ b/stats_node.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 0d65a0a..0000000 --- a/test/test.js +++ /dev/null @@ -1,463 +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 converts subscripts to a linear index (simple)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 2; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 1; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 3; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function converts subscripts to a linear index (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, -1 ]; - offset = 0; - mode = [ 'throw' ]; - - idx = sub2ind( shape, strides, offset, 0, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `throw`, the function throws if provided a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'throw' ]; - - t.throws( foo, RangeError, 'throws a range error' ); - t.throws( bar, RangeError, 'throws a range error' ); - - t.end(); - - function foo() { - sub2ind( shape, strides, offset, 999999, 1, mode ); - } - - function bar() { - sub2ind( shape, strides, offset, 1, 999999, mode ); - } -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `wrap`, the function wraps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'wrap' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, -4, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `clamp`, the function clamps a subscript which exceeds array dimensions (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'clamp' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 2, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, 3, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -3, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 1, 5, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a dimension index `mode` is `normalize`, the function normalizes negative subscripts (offset=0)', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2 ]; - strides = [ -2, 1 ]; - offset = 0; - mode = [ 'normalize' ]; - - idx = sub2ind( shape, strides, offset, 1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, 0, mode ); - t.strictEqual( idx, 2, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, 0, -1, mode ); - t.strictEqual( idx, 1, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -2, 0, mode ); - t.strictEqual( idx, 0, 'returns expected value' ); - - idx = sub2ind( shape, strides, offset, -1, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports providing mixed modes', function test( t ) { - var strides; - var offset; - var shape; - var mode; - var idx; - - shape = [ 2, 2, 2 ]; - strides = [ 4, 2, 1 ]; - offset = 0; - mode = [ 'wrap', 'clamp' ]; - - idx = sub2ind( shape, strides, offset, -2, 10, -1, mode ); - t.strictEqual( idx, 3, 'returns expected value' ); - - t.end(); -});